Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#289 - Add register, update and delete model group functionality to support Model Access Control #332

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
a2ffe54
init
rawwar Nov 3, 2023
7bef831
add search, delete and update
rawwar Nov 4, 2023
61c3090
Merge branch 'main' of https://github.com/opensearch-project/opensear…
rawwar Nov 4, 2023
a89bb39
add tests for register model group
rawwar Nov 4, 2023
3bbea93
update cluster to 2.11
rawwar Nov 4, 2023
ca765ec
test skipif
rawwar Nov 4, 2023
4c6a7fd
fix
rawwar Nov 4, 2023
af60958
add tests
rawwar Nov 4, 2023
cde4e1f
update matrix
rawwar Nov 4, 2023
28040ee
cancel in progress
rawwar Nov 4, 2023
d8fc9b2
update concurrency
rawwar Nov 4, 2023
cda4c08
job level concurrency
rawwar Nov 4, 2023
1ebeb1a
fix
rawwar Nov 4, 2023
1b72089
fix
rawwar Nov 4, 2023
e27daa3
fix tests
rawwar Nov 4, 2023
7edafe9
tests passing
rawwar Nov 4, 2023
2e0f9c4
isort fix
rawwar Nov 4, 2023
f9bc8c8
fix action
rawwar Nov 4, 2023
24ea966
fix action
rawwar Nov 4, 2023
84848e2
fix action
rawwar Nov 4, 2023
08256f6
fix
rawwar Nov 4, 2023
9547db3
update changelog
rawwar Nov 4, 2023
06f097d
fix os dockerfile
rawwar Nov 4, 2023
594baad
test
rawwar Nov 5, 2023
203aa86
pass opensearch version
rawwar Nov 5, 2023
19fdf80
fix
rawwar Nov 5, 2023
6bdcfcd
fix
rawwar Nov 5, 2023
76fcd84
fix
rawwar Nov 5, 2023
50bacd4
update OS dockerfile
rawwar Nov 5, 2023
b5133b9
fix failing tests
rawwar Nov 5, 2023
2b529a3
update dockerfile for 2.11.0
rawwar Nov 5, 2023
b61c1e3
remove disable warning
rawwar Nov 6, 2023
d5d5830
fix upload model
rawwar Nov 6, 2023
8f46cf9
fix lint
rawwar Nov 6, 2023
d2f832e
fix lint
rawwar Nov 6, 2023
286716e
Merge branch 'main' of https://github.com/opensearch-project/opensear…
rawwar Nov 6, 2023
24cb85c
include reference
rawwar Nov 6, 2023
078443f
pr fixes
rawwar Nov 6, 2023
c5cbde6
lint fix
rawwar Nov 6, 2023
c8dd748
fix lint
rawwar Nov 6, 2023
05a42b2
fix tests
rawwar Nov 6, 2023
4e47809
skip
rawwar Nov 6, 2023
bdf1201
fix lint
rawwar Nov 6, 2023
df6c069
fix lint and increase coverage
rawwar Nov 6, 2023
62b5601
fix lint
rawwar Nov 6, 2023
1993945
fix
rawwar Nov 6, 2023
2c6b346
feedback fixes
rawwar Nov 6, 2023
3b16fed
fix
rawwar Nov 9, 2023
d8479ff
lint fix
rawwar Nov 9, 2023
99a3660
fix test cases
rawwar Nov 9, 2023
ba60da7
pr feedback fixes
rawwar Nov 13, 2023
075a763
revert
rawwar Nov 13, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions opensearch_py_ml/ml_commons/ml_commons_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
)
from opensearch_py_ml.ml_commons.model_execute import ModelExecute
from opensearch_py_ml.ml_commons.model_uploader import ModelUploader
from opensearch_py_ml.ml_commons.model_access_control import ModelAccessControl


class MLCommonClient:
Expand All @@ -35,6 +36,7 @@ def __init__(self, os_client: OpenSearch):
self._client = os_client
self._model_uploader = ModelUploader(os_client)
self._model_execute = ModelExecute(os_client)
self.model_access_control = ModelAccessControl(os_client)
rawwar marked this conversation as resolved.
Show resolved Hide resolved

def execute(self, algorithm_name: str, input_json: dict) -> dict:
"""
Expand Down
87 changes: 87 additions & 0 deletions opensearch_py_ml/ml_commons/model_access_control.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
from opensearchpy import OpenSearch
from typing import List
from opensearch_py_ml.ml_commons.ml_common_utils import ML_BASE_URI
from opensearch_py_ml.exceptions.ml_commons import InvalidParameterError

ACCESS_MODES = ["public", "private", "restricted"]


class ModelAccessControl:
API_ENDPOINT = "model_group"

def __init__(self, os_client: OpenSearch):
self.client = os_client

def register_model_group(
self,
name: str,
description: str,
access_mode: str,
backend_roles: List[str],
add_all_backend_roles=False,
):
# if not isinstance(name, str):
rawwar marked this conversation as resolved.
Show resolved Hide resolved
# raise TypeError(f"name should be of type string. Not {type(name)}")

# if not isinstance(description, str):
# raise TypeError(
# f"description should be of type string. Not {type(description)}"
# )

# if not isinstance(access_mode, str):
# if not access_mode in ACCESS_MODES:
# raise InvalidParameterError(
# "access_mode", "unexpected value", ACCESS_MODES, access_mode
# )
# if access_mode == "restricted":
# if add_all_backend_roles:
# if isinstance(backend_roles, list) and len(backend_roles) > 0:
# raise Exception(
# "If access_mode is restricted and add_all_backend_roles is True,"
# "backend_roles should not be given"
# )
# else:
# if isinstance(backend_roles, list) and len(backend_roles) == 0:
# raise Exception(
# "If access_mode is restricted and add_all_backend_roles is False,"
# "backend_roles parameter is mandatory"
# )

body = {
"name": name,
"description": description,
"access_mode": access_mode,
"backend_roles": backend_roles,
"add_all_backend_roles": add_all_backend_roles
}

return self.client.transport.perform_request(
method="POST", url=f"{ML_BASE_URI}/{self.API_ENDPOINT}/_register", body=body
)

def update_model_group(
self,
name: str,
description: str,
access_mode: str,
backend_roles: List[str],
add_all_backend_roles=False,
):

body = {
"name": name,
"description": description,
"access_mode": access_mode,
"backend_roles": backend_roles,
"add_all_backend_roles": add_all_backend_roles
}

return self.client.transport.perform_request(
method="PUT", url=f"{ML_BASE_URI}/{self.API_ENDPOINT}/_update", body=body
)

def delete_model_group(self, model_group_id):

return self.client.transport.perform_request(
method="DELETE", url=f"{ML_BASE_URI}/{self.API_ENDPOINT}/{model_group_id}"
)
Loading