Skip to content

Commit 4c21993

Browse files
authored
feat: Add endpoind_id arg to Endpoint#create (#1168)
Thank you for opening a Pull Request! Before submitting your PR, there are a few things you can do to make sure it goes smoothly: - [x] Make sure to open an issue as a [bug/issue](https://github.com/googleapis/python-aiplatform/issues/new/choose) before writing your code! That way we can discuss the change, evaluate designs, and agree on the general idea - [x] Ensure the tests and linter pass - [x] Code coverage does not decrease (if any source code was changed) - [x] Appropriate docs were updated (if necessary) Fixes #1169 🦕
1 parent 10f95cd commit 4c21993

File tree

2 files changed

+56
-0
lines changed

2 files changed

+56
-0
lines changed

google/cloud/aiplatform/models.py

+26
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,7 @@ def create(
208208
encryption_spec_key_name: Optional[str] = None,
209209
sync=True,
210210
create_request_timeout: Optional[float] = None,
211+
endpoint_id: Optional[str] = None,
211212
) -> "Endpoint":
212213
"""Creates a new endpoint.
213214
@@ -257,6 +258,17 @@ def create(
257258
be immediately returned and synced when the Future has completed.
258259
create_request_timeout (float):
259260
Optional. The timeout for the create request in seconds.
261+
endpoint_id (str):
262+
Optional. The ID to use for endpoint, which will become
263+
the final component of the endpoint resource name. If
264+
not provided, Vertex AI will generate a value for this
265+
ID.
266+
267+
This value should be 1-10 characters, and valid
268+
characters are /[0-9]/. When using HTTP/JSON, this field
269+
is populated based on a query string argument, such as
270+
``?endpoint_id=12345``. This is the fallback for fields
271+
that are not included in either the URI or the body.
260272
Returns:
261273
endpoint (endpoint.Endpoint):
262274
Created endpoint.
@@ -288,6 +300,7 @@ def create(
288300
),
289301
sync=sync,
290302
create_request_timeout=create_request_timeout,
303+
endpoint_id=endpoint_id,
291304
)
292305

293306
@classmethod
@@ -305,6 +318,7 @@ def _create(
305318
encryption_spec: Optional[gca_encryption_spec.EncryptionSpec] = None,
306319
sync=True,
307320
create_request_timeout: Optional[float] = None,
321+
endpoint_id: Optional[str] = None,
308322
) -> "Endpoint":
309323
"""Creates a new endpoint by calling the API client.
310324
@@ -350,6 +364,17 @@ def _create(
350364
Whether to create this endpoint synchronously.
351365
create_request_timeout (float):
352366
Optional. The timeout for the create request in seconds.
367+
endpoint_id (str):
368+
Optional. The ID to use for endpoint, which will become
369+
the final component of the endpoint resource name. If
370+
not provided, Vertex AI will generate a value for this
371+
ID.
372+
373+
This value should be 1-10 characters, and valid
374+
characters are /[0-9]/. When using HTTP/JSON, this field
375+
is populated based on a query string argument, such as
376+
``?endpoint_id=12345``. This is the fallback for fields
377+
that are not included in either the URI or the body.
353378
Returns:
354379
endpoint (endpoint.Endpoint):
355380
Created endpoint.
@@ -369,6 +394,7 @@ def _create(
369394
operation_future = api_client.create_endpoint(
370395
parent=parent,
371396
endpoint=gapic_endpoint,
397+
endpoint_id=endpoint_id,
372398
metadata=metadata,
373399
timeout=create_request_timeout,
374400
)

tests/unit/aiplatform/test_endpoints.py

+30
Original file line numberDiff line numberDiff line change
@@ -547,6 +547,7 @@ def test_init_aiplatform_with_encryption_key_name_and_create_endpoint(
547547
create_endpoint_mock.assert_called_once_with(
548548
parent=_TEST_PARENT,
549549
endpoint=expected_endpoint,
550+
endpoint_id=None,
550551
metadata=(),
551552
timeout=None,
552553
)
@@ -573,13 +574,39 @@ def test_create(self, create_endpoint_mock, sync):
573574
create_endpoint_mock.assert_called_once_with(
574575
parent=_TEST_PARENT,
575576
endpoint=expected_endpoint,
577+
endpoint_id=None,
576578
metadata=(),
577579
timeout=None,
578580
)
579581

580582
expected_endpoint.name = _TEST_ENDPOINT_NAME
581583
assert my_endpoint._gca_resource == expected_endpoint
582584

585+
@pytest.mark.usefixtures("get_endpoint_mock")
586+
@pytest.mark.parametrize("sync", [True, False])
587+
def test_create_with_endpoint_id(self, create_endpoint_mock, sync):
588+
my_endpoint = models.Endpoint.create(
589+
display_name=_TEST_DISPLAY_NAME,
590+
endpoint_id=_TEST_ID,
591+
description=_TEST_DESCRIPTION,
592+
sync=sync,
593+
create_request_timeout=None,
594+
)
595+
if not sync:
596+
my_endpoint.wait()
597+
598+
expected_endpoint = gca_endpoint.Endpoint(
599+
display_name=_TEST_DISPLAY_NAME,
600+
description=_TEST_DESCRIPTION,
601+
)
602+
create_endpoint_mock.assert_called_once_with(
603+
parent=_TEST_PARENT,
604+
endpoint=expected_endpoint,
605+
endpoint_id=_TEST_ID,
606+
metadata=(),
607+
timeout=None,
608+
)
609+
583610
@pytest.mark.usefixtures("get_endpoint_mock")
584611
@pytest.mark.parametrize("sync", [True, False])
585612
def test_create_with_timeout(self, create_endpoint_mock, sync):
@@ -599,6 +626,7 @@ def test_create_with_timeout(self, create_endpoint_mock, sync):
599626
create_endpoint_mock.assert_called_once_with(
600627
parent=_TEST_PARENT,
601628
endpoint=expected_endpoint,
629+
endpoint_id=None,
602630
metadata=(),
603631
timeout=180.0,
604632
)
@@ -642,6 +670,7 @@ def test_create_with_description(self, create_endpoint_mock, sync):
642670
create_endpoint_mock.assert_called_once_with(
643671
parent=_TEST_PARENT,
644672
endpoint=expected_endpoint,
673+
endpoint_id=None,
645674
metadata=(),
646675
timeout=None,
647676
)
@@ -665,6 +694,7 @@ def test_create_with_labels(self, create_endpoint_mock, sync):
665694
create_endpoint_mock.assert_called_once_with(
666695
parent=_TEST_PARENT,
667696
endpoint=expected_endpoint,
697+
endpoint_id=None,
668698
metadata=(),
669699
timeout=None,
670700
)

0 commit comments

Comments
 (0)