From: subhash kumar singh Date: Tue, 12 Nov 2024 14:13:37 +0000 (+0000) Subject: Implement the basic implementation for delete TJ X-Git-Tag: 3.0.0~39 X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=commitdiff_plain;h=764599181949d0a9ef393ba6641d5bdb6444118d;p=aiml-fw%2Fawmf%2Ftm.git Implement the basic implementation for delete TJ Implemented deletion of Training Job as per spec defined structure. TODO: Cancel the training job on delete request. Change-Id: I236c837907c01d784f59d2bfe299a898b94a0253 Signed-off-by: subhash kumar singh --- diff --git a/tests/test.env b/tests/test.env index a7ba1e9..c334695 100644 --- a/tests/test.env +++ b/tests/test.env @@ -31,4 +31,5 @@ PS_PORT="30001" ACCESS_CONTROL_ALLOW_ORIGIN="http://localhost:32005" PIPELINE="{'timeseries':'qoe_pipeline'}" MODEL_MANAGEMENT_SERVICE_IP=localhost -MODEL_MANAGEMENT_SERVICE_PORT=12343 \ No newline at end of file +MODEL_MANAGEMENT_SERVICE_PORT=12343 +CONF_LOG=tests/common/conf_log.yaml \ No newline at end of file diff --git a/trainingmgr/__init__.py b/trainingmgr/__init__.py index e69de29..677395c 100644 --- a/trainingmgr/__init__.py +++ b/trainingmgr/__init__.py @@ -0,0 +1,17 @@ +# ================================================================================== +# +# Copyright (c) 2024 Samsung Electronics Co., Ltd. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# ================================================================================== \ No newline at end of file diff --git a/trainingmgr/common/trainingmgr_config.py b/trainingmgr/common/trainingmgr_config.py index c11ab10..ac85f7e 100644 --- a/trainingmgr/common/trainingmgr_config.py +++ b/trainingmgr/common/trainingmgr_config.py @@ -19,7 +19,7 @@ """ This module is for loading training manager configuration. """ - +import os from os import getenv from trainingmgr.common.tmgr_logger import TMLogger @@ -63,7 +63,8 @@ class TrainingMgrConfig: self.__allow_control_access_origin = getenv('ACCESS_CONTROL_ALLOW_ORIGIN').rstrip() if getenv('ACCESS_CONTROL_ALLOW_ORIGIN') is not None else None self.__pipeline = getenv('PIPELINE').rstrip() if getenv('PIPELINE') is not None else None - self.tmgr_logger = TMLogger("common/conf_log.yaml") + conf_filepath = getenv("CONF_LOG", "common/conf_log.yaml") + self.tmgr_logger = TMLogger(conf_filepath) self.__logger = self.tmgr_logger.logger self.__initialized = True diff --git a/trainingmgr/controller/__init__.py b/trainingmgr/controller/__init__.py new file mode 100644 index 0000000..677395c --- /dev/null +++ b/trainingmgr/controller/__init__.py @@ -0,0 +1,17 @@ +# ================================================================================== +# +# Copyright (c) 2024 Samsung Electronics Co., Ltd. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# ================================================================================== \ No newline at end of file diff --git a/trainingmgr/controller/trainingjob_controller.py b/trainingmgr/controller/trainingjob_controller.py new file mode 100644 index 0000000..db18111 --- /dev/null +++ b/trainingmgr/controller/trainingjob_controller.py @@ -0,0 +1,42 @@ +# ================================================================================== +# +# Copyright (c) 2024 Samsung Electronics Co., Ltd. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# ================================================================================== +from flask import Blueprint, jsonify +from trainingmgr.common.trainingmgr_config import TrainingMgrConfig +from trainingmgr.service.training_job_service import delete_training_job + +training_job_controller = Blueprint('training_job_controller', __name__) +LOGGER = TrainingMgrConfig().logger + +@training_job_controller.route('/training-jobs/', methods=['DELETE']) +def delete_trainingjob(training_job_id): + TrainingMgrConfig.logger + LOGGER.debug(f'delete training job : {training_job_id}') + try: + if delete_training_job(str(training_job_id)): + LOGGER.debug(f'training job with {training_job_id} is deleted successfully.') + return '', 204 + else: + LOGGER.debug(f'training job with {training_job_id} does not exist.') + return jsonify({ + 'message': 'training job with given id is not found' + }), 500 + + except Exception as e: + return jsonify({ + 'message': str(e) + }), 500 \ No newline at end of file diff --git a/trainingmgr/db/trainingjob_db.py b/trainingmgr/db/trainingjob_db.py index b52da7b..94c8cd0 100644 --- a/trainingmgr/db/trainingjob_db.py +++ b/trainingmgr/db/trainingjob_db.py @@ -24,6 +24,7 @@ from trainingmgr.models import db, TrainingJob, FeatureGroup from trainingmgr.constants.steps import Steps from trainingmgr.constants.states import States from sqlalchemy.sql import func +from sqlalchemy.exc import NoResultFound from trainingmgr.common.trainingConfig_parser import getField @@ -286,3 +287,26 @@ def delete_trainingjob_version(trainingjob_name, version): except Exception as err: raise DBException(DB_QUERY_EXEC_ERROR + \ "delete_trainingjob_version" + str(err)) + +def delete_trainingjob_by_id(id: int): + """ + This function delets the trainingjob using the id which is PK + + Args: + id (int): Primary key ID of the trainingjob + + Returns: + bool: True if the trainingjob was not found and dleted, false if not found. + """ + try: + tj = db.session.query(TrainingJob).get(id) + if tj: + db.session.delete(tj) + db.session.commit() + return True + + except NoResultFound: + return False + except Exception as e: + db.session.rollback() + raise DBException(f'{DB_QUERY_EXEC_ERROR} : {str(e)}' ) diff --git a/trainingmgr/service/__init__.py b/trainingmgr/service/__init__.py new file mode 100644 index 0000000..677395c --- /dev/null +++ b/trainingmgr/service/__init__.py @@ -0,0 +1,17 @@ +# ================================================================================== +# +# Copyright (c) 2024 Samsung Electronics Co., Ltd. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# ================================================================================== \ No newline at end of file diff --git a/trainingmgr/service/training_job_service.py b/trainingmgr/service/training_job_service.py new file mode 100644 index 0000000..d03d9d0 --- /dev/null +++ b/trainingmgr/service/training_job_service.py @@ -0,0 +1,40 @@ +# ================================================================================== +# +# Copyright (c) 2024 Samsung Electronics Co., Ltd. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# ================================================================================== +from trainingmgr.db.trainingjob_db import delete_trainingjob_by_id +from trainingmgr.common.exceptions_utls import DBException + +def delete_training_job(training_job_id : int): + """ + This function handles the service to delete the training job resource by id. + + Args: + training_job_id (int): id of training job. + + Returns: + bool: boolean to represent if the trainingjob is deleted. + + Raises: + DBException: If there error during operation. + + """ + try: + #TODO: cancel training job from kubeflow training + return delete_trainingjob_by_id(id=training_job_id) + except Exception as err : + raise DBException(f"delete_trainining_job failed with exception : {str(err)}") + diff --git a/trainingmgr/trainingmgr_main.py b/trainingmgr/trainingmgr_main.py index 165eeff..018ccd0 100644 --- a/trainingmgr/trainingmgr_main.py +++ b/trainingmgr/trainingmgr_main.py @@ -59,13 +59,14 @@ from trainingmgr.db.trainingjob_db import add_update_trainingjob, get_trainingjo get_steps_state_db, change_field_of_latest_version, get_latest_version_trainingjob_name, get_info_of_latest_version, \ change_field_value_by_version, delete_trainingjob_version, change_in_progress_to_failed_by_latest_version, \ update_model_download_url, get_all_versions_info_by_name +from trainingmgr.controller.trainingjob_controller import training_job_controller from trainingmgr.common.trainingConfig_parser import validateTrainingConfig, getField APP = Flask(__name__) - +TRAININGMGR_CONFIG_OBJ = TrainingMgrConfig() from middleware.loggingMiddleware import LoggingMiddleware APP.wsgi_app = LoggingMiddleware(APP.wsgi_app) -TRAININGMGR_CONFIG_OBJ = None +APP.register_blueprint(training_job_controller) PS_DB_OBJ = None LOGGER = None MM_SDK = None @@ -1735,7 +1736,6 @@ def async_feature_engineering_status(): time.sleep(10) if __name__ == "__main__": - TRAININGMGR_CONFIG_OBJ = TrainingMgrConfig() try: if TRAININGMGR_CONFIG_OBJ.is_config_loaded_properly() is False: raise TMException("Not all configuration loaded.")