Skip to content

Commit 22e176b

Browse files
authored
Append uuid to endpoint name (#90)
* Add unit test and fix HyperPod Manager 1. Default namespace can be set by HyperpodManager.set_context() 2. Added unit tests for inference * Remove debug print * Append uuid to model name and endpoint name * minor fix in create method
1 parent 68d87de commit 22e176b

File tree

8 files changed

+30
-8
lines changed

8 files changed

+30
-8
lines changed

src/sagemaker/hyperpod/common/utils.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from pydantic import ValidationError
44
from kubernetes.client.exceptions import ApiException
55
from kubernetes import config
6+
import uuid
67

78

89
def validate_cluster_connection():
@@ -37,13 +38,13 @@ def handle_exception(e: Exception, name: str, namespace: str):
3738
raise Exception(f"Credentials unauthorized.") from e
3839
elif e.status == 403:
3940
raise Exception(
40-
f"Access denied to resource '{name}' in '{namespace}'."
41+
f"Access denied to resource '{name}' in namespace '{namespace}'."
4142
) from e
4243
if e.status == 404:
43-
raise Exception(f"Resource '{name}' not found in '{namespace}'.") from e
44+
raise Exception(f"Resource '{name}' not found in namespace '{namespace}'.") from e
4445
elif e.status == 409:
4546
raise Exception(
46-
f"Resource '{name}' already exists in '{namespace}'."
47+
f"Resource '{name}' already exists in namespace '{namespace}'."
4748
) from e
4849
elif 500 <= e.status < 600:
4950
raise Exception("Kubernetes API internal server error.") from e
@@ -54,3 +55,6 @@ def handle_exception(e: Exception, name: str, namespace: str):
5455
raise Exception("Response did not match expected schema.") from e
5556

5657
raise e
58+
59+
def append_uuid(name: str) -> str:
60+
return f"{name}-{str(uuid.uuid4())[:4]}"

src/sagemaker/hyperpod/inference/config/common.py

Whitespace-only changes.

src/sagemaker/hyperpod/inference/config/hp_endpoint_config.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from pydantic import BaseModel, ConfigDict, Field
22
from typing import Optional, List, Dict, Union, Literal
3+
from sagemaker.hyperpod.common.config import *
34

45

56
class Dimensions(BaseModel):

src/sagemaker/hyperpod/inference/config/hp_jumpstart_endpoint_config.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from pydantic import BaseModel, ConfigDict, Field
22
from typing import Optional, List, Dict, Union, Literal
3+
from sagemaker.hyperpod.common.config import *
34

45

56
class Dimensions(BaseModel):

src/sagemaker/hyperpod/inference/hp_endpoint.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from sagemaker.hyperpod.common.config.metadata import Metadata
22
from sagemaker.hyperpod.inference.config.constants import *
3+
from sagemaker.hyperpod.common.utils import append_uuid
34
from sagemaker.hyperpod.inference.config.hp_endpoint_config import (
45
InferenceEndpointConfigStatus,
56
_HPEndpoint,
@@ -27,14 +28,18 @@ def create(
2728
self.get_logger().setLevel(logging.DEBUG)
2829
else:
2930
self.get_logger().setLevel(logging.INFO)
31+
3032
spec = _HPEndpoint(**self.model_dump(by_alias=True, exclude_none=True))
3133

3234
if not name:
33-
name = spec.modelName
35+
name = append_uuid(spec.modelName)
3436

3537
if not namespace:
3638
namespace = get_default_namespace()
3739

40+
if spec.endpointName:
41+
spec.endpointName = append_uuid(spec.endpointName)
42+
3843
self.call_create_api(
3944
name=name, # use model name as metadata name
4045
kind=INFERENCE_ENDPOINT_CONFIG_KIND,
@@ -60,11 +65,14 @@ def create_from_dict(
6065
spec = _HPEndpoint.model_validate(input, by_name=True)
6166

6267
if not name:
63-
name = spec.modelName
68+
name = append_uuid(spec.modelName)
6469

6570
if not namespace:
6671
namespace = get_default_namespace()
6772

73+
if spec.endpointName:
74+
spec.endpointName = append_uuid(spec.endpointName)
75+
6876
self.call_create_api(
6977
name=name, # use model name as metadata name
7078
kind=INFERENCE_ENDPOINT_CONFIG_KIND,

src/sagemaker/hyperpod/inference/hp_jumpstart_endpoint.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from sagemaker.hyperpod.inference.config.constants import *
22
from sagemaker.hyperpod.inference.hp_endpoint_base import HPEndpointBase
33
from sagemaker.hyperpod.common.config.metadata import Metadata
4+
from sagemaker.hyperpod.common.utils import append_uuid
45
from sagemaker.hyperpod.inference.config.hp_jumpstart_endpoint_config import (
56
_HPJumpStartEndpoint,
67
JumpStartModelStatus,
@@ -31,7 +32,10 @@ def create(
3132
spec = _HPJumpStartEndpoint(**self.model_dump(by_alias=True, exclude_none=True))
3233

3334
if not name:
34-
name = spec.model.modelId
35+
name = append_uuid(spec.model.modelId)
36+
37+
if spec.sageMakerEndpoint and spec.sageMakerEndpoint.name:
38+
spec.sageMakerEndpoint.name = append_uuid(spec.sageMakerEndpoint.name)
3539

3640
if not namespace:
3741
namespace = get_default_namespace()
@@ -61,7 +65,10 @@ def create_from_dict(
6165
spec = _HPJumpStartEndpoint.model_validate(input, by_name=True)
6266

6367
if not name:
64-
name = spec.model.modelId
68+
name = append_uuid(spec.model.modelId)
69+
70+
if spec.sageMakerEndpoint and spec.sageMakerEndpoint.name:
71+
spec.sageMakerEndpoint.name = append_uuid(spec.sageMakerEndpoint.name)
6572

6673
if not namespace:
6774
namespace = get_default_namespace()
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from sagemaker.hyperpod.common.config import *

test/unit_tests/common/test_utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def test_handle_api_exception_404(self):
2929
with self.assertRaises(Exception) as context:
3030
handle_exception(exception, "test-job", "default")
3131
self.assertIn(
32-
"Resource 'test-job' not found in 'default'", str(context.exception)
32+
"Resource 'test-job' not found in namespace 'default'", str(context.exception)
3333
)
3434

3535
def test_handle_api_exception_409(self):

0 commit comments

Comments
 (0)