From: rajdeep11 Date: Thu, 26 Dec 2024 11:15:09 +0000 (+0530) Subject: changes for url_prefix and featuregroup controller and service X-Git-Tag: 3.0.0~3^2 X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=commitdiff_plain;h=refs%2Fchanges%2F80%2F13980%2F2;p=aiml-fw%2Fawmf%2Ftm.git changes for url_prefix and featuregroup controller and service Description: 1) adding url_prefix to trainingjob_controller and featuregroup_controller 2) adding get_all_featuregroup to featuregroup service 3) fixing the UNIQUE_VOILATION error in featuregroup creation Change-Id: I67359950734b9816b4d7b45fd5038bae7835a99e Signed-off-by: rajdeep11 --- diff --git a/trainingmgr/controller/featuregroup_controller.py b/trainingmgr/controller/featuregroup_controller.py index af4ace4..46909cf 100644 --- a/trainingmgr/controller/featuregroup_controller.py +++ b/trainingmgr/controller/featuregroup_controller.py @@ -25,6 +25,7 @@ from trainingmgr.common.trainingmgr_util import check_trainingjob_name_or_featur from trainingmgr.db.featuregroup_db import add_featuregroup, delete_feature_group_by_name from trainingmgr.common.trainingmgr_config import TrainingMgrConfig from trainingmgr.schemas import FeatureGroupSchema +from trainingmgr.service.featuregroup_service import get_all_featuregroups @@ -32,6 +33,7 @@ featuregroup_controller = Blueprint('featuregroup_controller', __name__) TRAININGMGR_CONFIG_OBJ = TrainingMgrConfig() LOGGER = TRAININGMGR_CONFIG_OBJ.logger MIMETYPE_JSON = "application/json" +featuregroups_schema = FeatureGroupSchema(many=True) @featuregroup_controller.route('/featureGroup', methods=['POST']) def create_feature_group(): @@ -118,10 +120,47 @@ def create_feature_group(): return {"Exception": str(err)}, 400 except DBException as err: LOGGER.error(f"Failed to create the feature Group {str(err)}") + if "already exist" in str(err): + return {"Exception": str(err)}, 409 return {"Exception": str(err)}, 400 except Exception as e: api_response = {"Exception":str(e)} LOGGER.error(f"Failed to create the feature Group {str(err)}") jsonify(json.dumps(api_response)), 500 - return jsonify(api_response), 201 \ No newline at end of file + return jsonify(api_response), 201 + +@featuregroup_controller.route('/featureGroup', methods=['GET']) +def get_feature_group(): + """ + Rest endpoint to fetch all the feature groups + + Args in function: none + Required Args in json: + no json required + + Returns: + json: + FeatureGroups: list + list of dictionaries. + dictionaries contains: + featuregroup_name: str + name of feature group + features: str + name of features + datalake: str + datalake + dme: boolean + whether to enable dme + + """ + LOGGER.debug("Request for getting all feature groups") + api_response={} + response_code=status.HTTP_500_INTERNAL_SERVER_ERROR + try: + api_response=featuregroups_schema.dump(get_all_featuregroups()) + response_code=status.HTTP_200_OK + except Exception as err: + api_response = {"Exception": "Failed to get featuregroups"} + LOGGER.error(str(err)) + return jsonify({"FeatureGroups":api_response}), response_code \ No newline at end of file diff --git a/trainingmgr/db/featuregroup_db.py b/trainingmgr/db/featuregroup_db.py index 0187a75..6db5398 100644 --- a/trainingmgr/db/featuregroup_db.py +++ b/trainingmgr/db/featuregroup_db.py @@ -17,9 +17,13 @@ # ================================================================================== from trainingmgr.common.exceptions_utls import DBException -from psycopg2.errorcodes import UNIQUE_VIOLATION +from sqlalchemy.exc import IntegrityError +from psycopg2.errors import UniqueViolation from psycopg2 import errors from trainingmgr.models import db, FeatureGroup +from trainingmgr.common.trainingmgr_config import TrainingMgrConfig + +LOGGER = TrainingMgrConfig().logger DB_QUERY_EXEC_ERROR = "Failed to execute query in " @@ -30,9 +34,12 @@ def add_featuregroup(featuregroup): try: db.session.add(featuregroup) db.session.commit() - except errors.lookup(UNIQUE_VIOLATION) as e: - raise DBException(DB_QUERY_EXEC_ERROR + " "+ str(e)) + except IntegrityError as e: + if isinstance(e.orig, UniqueViolation): + LOGGER.error(f"failed to add featuregroup due to: {str(e)}") + raise DBException(f"Featuregroup with featuregroup_name {featuregroup.featuregroup_name} already exist") except Exception as err: + LOGGER.error(f"failed to add featuregroup due to: {str(err)}") db.session.rollback() raise DBException(DB_QUERY_EXEC_ERROR + " failed to add feature group") diff --git a/trainingmgr/pipeline/mme_mgr.py b/trainingmgr/pipeline/mme_mgr.py index 076cd7b..5dd117d 100644 --- a/trainingmgr/pipeline/mme_mgr.py +++ b/trainingmgr/pipeline/mme_mgr.py @@ -54,7 +54,7 @@ class MmeMgr: This function returns the model information for given modelName and ModelVersion from MME """ try: - url = f'http://{self.mme_ip}:{self.mme_port}/models/?model-name={modelName}&model-version={int(modelVersion)}' + url = f'http://{self.mme_ip}:{self.mme_port}/ai-ml-model-discovery/v1/models/?model-name={modelName}&model-version={int(modelVersion)}' LOGGER.debug(f"Requesting modelInfo from: {url}") response = requests.get(url) if response.status_code == 200: diff --git a/trainingmgr/service/featuregroup_service.py b/trainingmgr/service/featuregroup_service.py index 4b021f5..4f93ea6 100644 --- a/trainingmgr/service/featuregroup_service.py +++ b/trainingmgr/service/featuregroup_service.py @@ -16,7 +16,7 @@ # # ================================================================================== -from trainingmgr.db.featuregroup_db import get_feature_group_by_name_db, get_feature_groups_from_inputDataType_db +from trainingmgr.db.featuregroup_db import get_feature_group_by_name_db, get_feature_groups_db, get_feature_groups_from_inputDataType_db from trainingmgr.common.exceptions_utls import TMException, DBException from trainingmgr.common.trainingmgr_config import TrainingMgrConfig @@ -47,6 +47,15 @@ def get_featuregroup_from_inputDataType(inputDataType): raise TMException(f"get get_featuregroup_from_inputDataType service failed with exception : {str(err)}") except Exception as err: raise err + +def get_all_featuregroups(): + LOGGER.debug(f'service for get all featuregroups') + try: + featuregroups = get_feature_groups_db() + return featuregroups + except Exception as err: + LOGGER.error("Error occured during fetching all featuregroups from db") + raise TMException(f"get all featuregroups service failed with exception : {str(err)}") \ No newline at end of file diff --git a/trainingmgr/trainingmgr_main.py b/trainingmgr/trainingmgr_main.py index d9741fe..80f7bfd 100644 --- a/trainingmgr/trainingmgr_main.py +++ b/trainingmgr/trainingmgr_main.py @@ -52,8 +52,8 @@ APP = Flask(__name__) TRAININGMGR_CONFIG_OBJ = TrainingMgrConfig() from middleware.loggingMiddleware import LoggingMiddleware APP.wsgi_app = LoggingMiddleware(APP.wsgi_app) -APP.register_blueprint(featuregroup_controller) -APP.register_blueprint(training_job_controller) +APP.register_blueprint(featuregroup_controller, url_prefix='/ai-ml-model-training/v1') +APP.register_blueprint(training_job_controller, url_prefix='/ai-ml-model-training/v1') APP.register_blueprint(pipeline_controller) PS_DB_OBJ = None @@ -488,42 +488,6 @@ def feature_group_by_name(featuregroup_name): mimetype=MIMETYPE_JSON) -@APP.route('/featureGroup', methods=['GET']) -def get_feature_group(): - """ - Rest endpoint to fetch all the feature groups - - Args in function: none - Required Args in json: - no json required - - Returns: - json: - FeatureGroups: list - list of dictionaries. - dictionaries contains: - featuregroup_name: str - name of feature group - features: str - name of features - datalake: str - datalake - dme: boolean - whether to enable dme - - """ - LOGGER.debug("Request for getting all feature groups") - api_response={} - response_code=status.HTTP_500_INTERNAL_SERVER_ERROR - try: - api_response={"featuregroups": featuregroups_schema.dump(get_feature_groups_db())} - response_code=status.HTTP_200_OK - except Exception as err: - api_response = {"Exception": str(err)} - LOGGER.error(str(err)) - return APP.response_class(response=json.dumps(api_response), - status=response_code, - mimetype=MIMETYPE_JSON) @APP.route('/featureGroup', methods=['DELETE']) def delete_list_of_feature_group():