Skip to content

Commit 425a32f

Browse files
vinnysenthilgcf-owl-bot[bot]nayaknishantsasha-gitg
authored
feat: Add PrivateEndpoint class and HTTP methods (#1033)
* Add `network` to SDK initializer * Add urllib3 to library requirements * Fix network init() docstrings * Update Model/Endpoint docs to use top namespace * Add core Private Endpoint wrapper * Drop logs, add URI props * Lint, update typing for Prediction class * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md * Add bug refs, test stubs, minor fixes * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md * test commit * adding examples, slight changes * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md * adding deployed model check: q * adding deployed model check * minor changes, adding error catching for explanations * testing to get other fields * removing edge case * adding print statement for debugging explain * using GET instead of POST for explain * using GET instead of POST for explain * using GET instead of POST for explain * removing explain for now, adding model id * removing explain for now, adding model id * removing explain for now, adding model id * cleaned and added docstrings * adding explain back * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md * removing explain until working * cleaning up docstrings * create test done, working on predict * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md * added unit tests for PrivateEndpoint * test debugging * fixing unit tests * adding fixes * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md * formatting encryption_spec_key_name * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md * fixing comments * adjusting traffic for private endpoint * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md * adjusting traffic for private endpoint * adjusting traffic for private endpoint * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md * adding fixes * added delete for private Endpoint * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md * fixing traffic percentage * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md * using network instead of class, moving exceptions * cleaning up docstrings * adding fixes, delete testing * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md * adding fixes * adding Raises section to private Endpoint docstrings * added private Endpoint check in init, added to testing * added private Endpoint check in init, added to testing * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md * adding try/except inside functions, fixing tests, misc fixes * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md * reverting _validate_deploy_args method * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md * fixed type hint * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md * lint issue * lint issue * adding system tests * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md * adding system test changes * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md * adding shared_state to system test * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md * trying outside import * putting imports back inside * added system test changes * added system test changes * adding fixes * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md * fixing system test and init fixes * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md * adding fixes * adding fixes * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md * adding fixes * adding fixes * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md * added global network arg to associated classes * style formatting * docstring fixes * adding extra info to network arg docstring * adding extra info to network arg docstring * removing changes to noxfile * reverting noxfile * reverting noxfile * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md * reverting job files to not include global network * reverting initalizer to not include global network config * removing global network config * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md * added fix and test to models * added fix and test to models * simplifying delete method Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com> Co-authored-by: nayaknishant <[email protected]> Co-authored-by: sasha-gitg <[email protected]>
1 parent caa41ae commit 425a32f

File tree

8 files changed

+1329
-232
lines changed

8 files changed

+1329
-232
lines changed

google/cloud/aiplatform/__init__.py

+2
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
)
4545
from google.cloud.aiplatform import metadata
4646
from google.cloud.aiplatform.models import Endpoint
47+
from google.cloud.aiplatform.models import PrivateEndpoint
4748
from google.cloud.aiplatform.models import Model
4849
from google.cloud.aiplatform.model_evaluation import ModelEvaluation
4950
from google.cloud.aiplatform.jobs import (
@@ -136,6 +137,7 @@
136137
"Model",
137138
"ModelEvaluation",
138139
"PipelineJob",
140+
"PrivateEndpoint",
139141
"SequenceToSequencePlusForecastingTrainingJob",
140142
"TabularDataset",
141143
"Tensorboard",

google/cloud/aiplatform/initializer.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ def init(
9898
Raises:
9999
ValueError:
100100
If experiment_description is provided but experiment is not.
101-
If experiment_tensorboard is provided but expeirment is not.
101+
If experiment_tensorboard is provided but experiment is not.
102102
"""
103103

104104
if experiment_description and experiment is None:

google/cloud/aiplatform/models.py

+963-223
Large diffs are not rendered by default.

setup.py

+9-3
Original file line numberDiff line numberDiff line change
@@ -52,21 +52,25 @@
5252
"pandas >= 1.0.0",
5353
"pyarrow >= 6.0.1",
5454
]
55-
pipelines_extra_requires = [
55+
pipelines_extra_require = [
5656
"pyyaml>=5.3,<6",
5757
]
5858
datasets_extra_require = [
5959
"pyarrow >= 3.0.0, < 8.0dev",
6060
]
61+
private_endpoints_extra_require = [
62+
"urllib3 >=1.21.1, <1.27",
63+
]
6164
full_extra_require = list(
6265
set(
6366
tensorboard_extra_require
6467
+ metadata_extra_require
6568
+ xai_extra_require
6669
+ lit_extra_require
6770
+ featurestore_extra_require
68-
+ pipelines_extra_requires
71+
+ pipelines_extra_require
6972
+ datasets_extra_require
73+
+ private_endpoints_extra_require
7074
)
7175
)
7276
testing_extra_require = (
@@ -118,7 +122,9 @@
118122
"xai": xai_extra_require,
119123
"lit": lit_extra_require,
120124
"cloud_profiler": profiler_extra_require,
121-
"pipelines": pipelines_extra_requires,
125+
"pipelines": pipelines_extra_require,
126+
"datasets": datasets_extra_require,
127+
"private_endpoints": private_endpoints_extra_require,
122128
},
123129
python_requires=">=3.7",
124130
classifiers=[

tests/system/aiplatform/e2e_base.py

-1
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,6 @@ def tear_down_resources(self, shared_state: Dict[str, Any]):
173173
yield
174174

175175
# TODO(b/218310362): Add resource deletion system tests
176-
177176
# Bring all Endpoints to the front of the list
178177
# Ensures Models are undeployed first before we attempt deletion
179178
shared_state["resources"].sort(
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
# -*- coding: utf-8 -*-
2+
3+
# Copyright 2022 Google LLC
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
#
17+
import pytest
18+
19+
from google.cloud import aiplatform
20+
21+
from tests.system.aiplatform import e2e_base
22+
23+
# permanent_custom_mnist_model
24+
_MODEL_ID = "6430031960164270080"
25+
_PRIVATE_ENDPOINT_NETWORK = "projects/580378083368/global/networks/private-endpoint-vpc"
26+
27+
28+
@pytest.mark.usefixtures("tear_down_resources")
29+
class TestPrivateEndpoint(e2e_base.TestEndToEnd):
30+
31+
_temp_prefix = "temp_vertex_sdk_e2e"
32+
33+
def test_create_deploy_delete_private_endpoint(self, shared_state):
34+
# Collection of resources generated by this test, to be deleted during teardown
35+
shared_state["resources"] = []
36+
37+
aiplatform.init(
38+
project=e2e_base._PROJECT,
39+
location=e2e_base._LOCATION,
40+
)
41+
42+
private_endpoint = aiplatform.PrivateEndpoint.create(
43+
display_name=self._make_display_name("private_endpoint_test"),
44+
network=_PRIVATE_ENDPOINT_NETWORK,
45+
)
46+
shared_state["resources"].append(private_endpoint)
47+
48+
# Verify that the retrieved private Endpoint is the same
49+
my_private_endpoint = aiplatform.PrivateEndpoint(
50+
endpoint_name=private_endpoint.resource_name
51+
)
52+
assert private_endpoint.resource_name == my_private_endpoint.resource_name
53+
assert private_endpoint.display_name == my_private_endpoint.display_name
54+
55+
# Verify the endpoint is in the private Endpoint list
56+
list_private_endpoint = aiplatform.PrivateEndpoint.list()
57+
assert private_endpoint.resource_name in [
58+
private_endpoint.resource_name for private_endpoint in list_private_endpoint
59+
]
60+
61+
# Retrieve permanent model, deploy to private Endpoint, then undeploy
62+
my_model = aiplatform.Model(model_name=_MODEL_ID)
63+
64+
my_private_endpoint.deploy(model=my_model)
65+
assert my_private_endpoint._gca_resource.deployed_models
66+
67+
deployed_model_id = my_private_endpoint.list_models()[0].id
68+
my_private_endpoint.undeploy(deployed_model_id=deployed_model_id)
69+
assert not my_private_endpoint._gca_resource.deployed_models

0 commit comments

Comments
 (0)