Skip to content

Commit 692fb61

Browse files
Resolving conflicts
2 parents 7239ff2 + 3992f22 commit 692fb61

File tree

6 files changed

+129
-0
lines changed

6 files changed

+129
-0
lines changed

ads/aqua/constants.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
LIFECYCLE_DETAILS_MISSING_JOBRUN = "The associated JobRun resource has been deleted."
2828
READY_TO_DEPLOY_STATUS = "ACTIVE"
2929
READY_TO_FINE_TUNE_STATUS = "TRUE"
30+
PRIVATE_ENDPOINT_TYPE = "MODEL_DEPLOYMENT"
3031
AQUA_GA_LIST = ["id19sfcrra6z"]
3132
AQUA_MODEL_TYPE_SERVICE = "service"
3233
AQUA_MODEL_TYPE_CUSTOM = "custom"

ads/aqua/extension/ui_handler.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
from ads.aqua.common.decorator import handle_exceptions
1111
from ads.aqua.common.enums import Tags
12+
from ads.aqua.constants import PRIVATE_ENDPOINT_TYPE
1213
from ads.aqua.extension.base_handler import AquaAPIhandler
1314
from ads.aqua.extension.errors import Errors
1415
from ads.aqua.extension.utils import validate_function_parameters
@@ -71,6 +72,8 @@ def get(self, id=""):
7172
return self.list_vcn()
7273
elif paths.startswith("aqua/subnets"):
7374
return self.list_subnets()
75+
elif paths.startswith("aqua/privateendpoints"):
76+
return self.list_private_endpoints()
7477
elif paths.startswith("aqua/shapes/limit"):
7578
return self.get_shape_availability()
7679
elif paths.startswith("aqua/bucket/versioning"):
@@ -174,6 +177,18 @@ def list_subnets(self, **kwargs):
174177
)
175178
)
176179

180+
def list_private_endpoints(self, **kwargs):
181+
"""Lists the private endpoints in the specified compartment."""
182+
compartment_id = self.get_argument("compartment_id", default=COMPARTMENT_OCID)
183+
resource_type = self.get_argument(
184+
"resource_type", default=PRIVATE_ENDPOINT_TYPE
185+
)
186+
return self.finish(
187+
AquaUIApp().list_private_endpoints(
188+
compartment_id=compartment_id, resource_type=resource_type, **kwargs
189+
)
190+
)
191+
177192
def get_shape_availability(self, **kwargs):
178193
"""For a given compartmentId, resource limit name, and scope, returns the number of available resources associated
179194
with the given limit."""
@@ -247,6 +262,7 @@ def post(self, *args, **kwargs):
247262
("job/shapes/?([^/]*)", AquaUIHandler),
248263
("vcn/?([^/]*)", AquaUIHandler),
249264
("subnets/?([^/]*)", AquaUIHandler),
265+
("privateendpoints/?([^/]*)", AquaUIHandler),
250266
("shapes/limit/?([^/]*)", AquaUIHandler),
251267
("bucket/versioning/?([^/]*)", AquaUIHandler),
252268
("containers/?([^/]*)", AquaUIHandler),

ads/aqua/ui.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
from ads.aqua.common.enums import Tags
1919
from ads.aqua.common.errors import AquaResourceAccessError, AquaValueError
2020
from ads.aqua.common.utils import get_container_config, sanitize_response
21+
from ads.aqua.constants import PRIVATE_ENDPOINT_TYPE
2122
from ads.common import oci_client as oc
2223
from ads.common.auth import default_signer
2324
from ads.common.object_storage_details import ObjectStorageDetails
@@ -547,6 +548,32 @@ def list_subnets(self, **kwargs) -> list:
547548

548549
return sanitize_response(oci_client=vcn_client, response=res)
549550

551+
@telemetry(entry_point="plugin=ui&action=list_private_endpoints", name="aqua")
552+
def list_private_endpoints(self, **kwargs) -> list:
553+
"""Lists the private endpoints in the specified compartment.
554+
Data seicne private endpoints have two types: `NOTEBOOK_SESSION` and `MODEL_DEPLOYMENT`.
555+
This api will by default list `MODEL_DEPLOYMENT` type as needed by AQUA model deployment.
556+
557+
Parameters
558+
----------
559+
**kwargs
560+
Addtional arguments, such as `compartment_id`,
561+
for `list_data_science_private_endpoints <https://docs.oracle.com/en-us/iaas/tools/python/latest/api/data_science/client/oci.data_science.DataScienceClient.html#oci.data_science.DataScienceClient.list_data_science_private_endpoints>`_
562+
563+
Returns
564+
-------
565+
json representation of `oci.data_science.models.DataSciencePrivateEndpointSummary`.
566+
"""
567+
compartment_id = kwargs.pop("compartment_id", COMPARTMENT_OCID)
568+
resource_type = kwargs.pop("resource_type", PRIVATE_ENDPOINT_TYPE)
569+
logger.info(f"Loading private endpoints from compartment: {compartment_id}")
570+
571+
res = self.ds_client.list_data_science_private_endpoints(
572+
compartment_id=compartment_id, data_science_resource_type=resource_type
573+
).data
574+
575+
return sanitize_response(oci_client=self.ds_client, response=res)
576+
550577
@telemetry(entry_point="plugin=ui&action=get_shape_availability", name="aqua")
551578
def get_shape_availability(self, **kwargs):
552579
"""
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
[
2+
{
3+
"compartment_id": "ocid1.compartment.oc1..<OCID>",
4+
"defined_tags": {},
5+
"display_name": "datascienceprivateendpoint20241024145113",
6+
"freeform_tags": {},
7+
"system_tags": {},
8+
"id": "ocid1.datascienceprivateendpointint.oc1.iad.<OCID>",
9+
"lifecycle_state": "ACTIVE",
10+
"data_science_resource_type": "MODEL_DEPLOYMENT",
11+
"created_by": "ocid1.datasciencenotebooksessionint.oc1.iad.<OCID>",
12+
"subnet_id": "ocid1.subnet.oc1.iad.<OCID>",
13+
"fqdn": "<OCID>.md2-pe.modeldeployment-int.us-ashburn-1.oci.oc-test.com",
14+
"time_created": "2024-10-24T14:51:13.883000Z",
15+
"time_updated": "2024-10-24T14:51:13.883000Z"
16+
},
17+
{
18+
"compartment_id": "ocid1.compartment.oc1..<OCID>",
19+
"defined_tags": {},
20+
"display_name": "datascienceprivateendpoint20241023220645",
21+
"freeform_tags": {},
22+
"system_tags": {},
23+
"id": "ocid1.datascienceprivateendpointint.oc1.iad.<OCID>",
24+
"lifecycle_state": "ACTIVE",
25+
"data_science_resource_type": "MODEL_DEPLOYMENT",
26+
"created_by": "ocid1.datasciencenotebooksessionint.oc1.iad.<OCID>",
27+
"subnet_id": "ocid1.subnet.oc1.iad.<OCID>",
28+
"fqdn": "<OCID>.md2-pe.modeldeployment-int.us-ashburn-1.oci.oc-test.com",
29+
"time_created": "2024-10-23T22:06:45.224000Z",
30+
"time_updated": "2024-10-23T22:06:45.224000Z"
31+
}
32+
]

tests/unitary/with_extras/aqua/test_ui.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -398,6 +398,48 @@ def test_list_subnets(self, mock_list_subnets):
398398
)
399399
assert len(results) == len(subnets)
400400

401+
def test_list_private_endpoints(self):
402+
"""Test to list the private endpoints in the specified compartment."""
403+
private_endpoints_list_json = os.path.join(
404+
self.curr_dir, f"test_data/ui/private_endpoints_list.json"
405+
)
406+
with open(private_endpoints_list_json, "r") as _file:
407+
private_endpoints = json.load(_file)
408+
409+
self.app.ds_client.list_data_science_private_endpoints = MagicMock(
410+
return_value=oci.response.Response(
411+
status=200,
412+
request=MagicMock(),
413+
headers=MagicMock(),
414+
data=[
415+
oci.data_science.models.DataSciencePrivateEndpointSummary(**pe)
416+
for pe in private_endpoints
417+
],
418+
)
419+
)
420+
421+
results = self.app.list_private_endpoints()
422+
expected_attributes = {
423+
"compartmentId",
424+
"definedTags",
425+
"displayName",
426+
"freeformTags",
427+
"systemTags",
428+
"id",
429+
"lifecycleState",
430+
"dataScienceResourceType",
431+
"createdBy",
432+
"subnetId",
433+
"fqdn",
434+
"timeCreated",
435+
"timeUpdated",
436+
}
437+
for result in results:
438+
self.assertTrue(
439+
expected_attributes.issuperset(set(result)), "Attributes mismatch"
440+
)
441+
assert len(results) == len(private_endpoints)
442+
401443
@patch.object(oci.limits.limits_client.LimitsClient, "get_resource_availability")
402444
def test_get_shape_availability(self, mock_get_resource_availability):
403445
"""Test whether the function returns the number of available resources associated with the given shape."""

tests/unitary/with_extras/aqua/test_ui_handler.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
class TestDataset:
2222
USER_COMPARTMENT_ID = "ocid1.compartment.oc1..<USER_COMPARTMENT_OCID>"
2323
USER_PROJECT_ID = "ocid1.datascienceproject.oc1.iad.<USER_PROJECT_OCID>"
24+
PRIVATE_ENDPOINT_RESOURCE_TYPE = "MODEL_DEPLOYMENT"
2425
DEPLOYMENT_SHAPE_NAME = "VM.GPU.A10.1"
2526
LIMIT_NAME = "ds-gpu-a10-count"
2627

@@ -150,6 +151,16 @@ def test_list_subnets(self, mock_list_subnets):
150151
compartment_id=TestDataset.USER_COMPARTMENT_ID, vcn_id="mock-vcn-id"
151152
)
152153

154+
@patch("ads.aqua.ui.AquaUIApp.list_private_endpoints")
155+
def test_list_private_endpoints(self, mock_list_private_endpoints):
156+
"""Test the get method to fetch list of private endpoints."""
157+
self.ui_handler.request.path = "aqua/privateendpoints"
158+
self.ui_handler.get()
159+
mock_list_private_endpoints.assert_called_with(
160+
compartment_id=TestDataset.USER_COMPARTMENT_ID,
161+
resource_type=TestDataset.PRIVATE_ENDPOINT_RESOURCE_TYPE,
162+
)
163+
153164
@patch("ads.aqua.ui.AquaUIApp.get_shape_availability")
154165
def test_get_shape_availability(self, mock_get_shape_availability):
155166
"""Test get shape availability."""

0 commit comments

Comments
 (0)