From: rajdeep11 Date: Sat, 19 Oct 2024 10:15:09 +0000 (+0530) Subject: adding marshmallow for validation X-Git-Tag: 3.0.0~59^2 X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=commitdiff_plain;h=630f6d213ca448276449bbfbfc365fe3adeaf0a7;p=aiml-fw%2Fawmf%2Ftm.git adding marshmallow for validation created folder schemas Change-Id: I5dafedd4848ae88ae1025053fafcc24b3d7ea1fc Signed-off-by: rajdeep11 --- diff --git a/requirements.txt b/requirements.txt index 113da19..ed9af3e 100644 --- a/requirements.txt +++ b/requirements.txt @@ -29,4 +29,6 @@ validators==0.20.0 Werkzeug==2.2.2 Flask-SQLAlchemy Flask-Migrate -psycopg2-binary \ No newline at end of file +psycopg2-binary==2.9.10 +marshmallow-sqlalchemy +flask-marshmallow \ No newline at end of file diff --git a/tox.ini b/tox.ini index 70bf1d4..af484df 100644 --- a/tox.ini +++ b/tox.ini @@ -44,6 +44,8 @@ deps= Werkzeug==2.2.2 validators==0.20.0 Flask-Migrate + marshmallow-sqlalchemy + flask-marshmallow setenv = cd = {toxinidir}/tests commands = diff --git a/trainingmgr/models/__init__.py b/trainingmgr/models/__init__.py index d6bf951..aa18ff7 100644 --- a/trainingmgr/models/__init__.py +++ b/trainingmgr/models/__init__.py @@ -1,3 +1,20 @@ +# ================================================================================== +# +# 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_sqlalchemy import SQLAlchemy db = SQLAlchemy() diff --git a/trainingmgr/models/featuregroup.py b/trainingmgr/models/featuregroup.py index b434280..2c59b6f 100644 --- a/trainingmgr/models/featuregroup.py +++ b/trainingmgr/models/featuregroup.py @@ -1,3 +1,20 @@ +# ================================================================================== +# +# 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 . import db class FeatureGroup(db.Model): @@ -13,9 +30,9 @@ class FeatureGroup(db.Model): db_org = db.Column(db.String(128), nullable=False) measurement = db.Column(db.String(1000), nullable=False) enable_dme = db.Column(db.Boolean, nullable=False) - measured_obj_class = db.Column(db.String(20000), nullable=False) - dme_port = db.Column(db.String(128), nullable=False) - source_name = db.Column(db.String(20000), nullable=False) + measured_obj_class = db.Column(db.String(20000), nullable=True) + dme_port = db.Column(db.String(128), nullable=True) + source_name = db.Column(db.String(20000), nullable=True) def __repr__(self): return f'' \ No newline at end of file diff --git a/trainingmgr/models/trainingjob.py b/trainingmgr/models/trainingjob.py index 85ae701..56f87bf 100644 --- a/trainingmgr/models/trainingjob.py +++ b/trainingmgr/models/trainingjob.py @@ -1,3 +1,21 @@ +# ================================================================================== +# +# 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 . import db from datetime import datetime from sqlalchemy.sql import func @@ -23,9 +41,9 @@ class TrainingJob(db.Model): model_url = db.Column(db.String(1000), nullable=False) notification_url = db.Column(db.String(1000), nullable=False) deletion_in_progress = db.Column(db.Boolean, nullable=False) - is_mme = db.Column(db.Boolean, nullable=False) - model_name = db.Column(db.String(128), nullable=False) - model_info = db.Column(db.String(1000), nullable=False) + is_mme = db.Column(db.Boolean, nullable=True) + model_name = db.Column(db.String(128), nullable=True) + model_info = db.Column(db.String(1000), nullable=True) def __repr__(self): return f'' \ No newline at end of file diff --git a/trainingmgr/schemas/__init__.py b/trainingmgr/schemas/__init__.py new file mode 100644 index 0000000..f23121c --- /dev/null +++ b/trainingmgr/schemas/__init__.py @@ -0,0 +1,8 @@ +from flask_marshmallow import Marshmallow + +ma = Marshmallow() + +from trainingmgr.schemas.trainingjob_schema import TrainingJobSchema +from trainingmgr.schemas.featuregroup_schema import FeatureGroupSchema + +__all_ = ['TrainingJobSchema', 'FeatureGroupSchema'] \ No newline at end of file diff --git a/trainingmgr/schemas/featuregroup_schema.py b/trainingmgr/schemas/featuregroup_schema.py new file mode 100644 index 0000000..ce2ae1d --- /dev/null +++ b/trainingmgr/schemas/featuregroup_schema.py @@ -0,0 +1,26 @@ +# ================================================================================== +# +# 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.schemas import ma +from trainingmgr.models import FeatureGroup + +class FeatureGroupSchema(ma.SQLAlchemyAutoSchema): + class Meta: + model = FeatureGroup + include_relationships = True + load_instance = True diff --git a/trainingmgr/schemas/trainingjob_schema.py b/trainingmgr/schemas/trainingjob_schema.py new file mode 100644 index 0000000..38b6a6d --- /dev/null +++ b/trainingmgr/schemas/trainingjob_schema.py @@ -0,0 +1,26 @@ +# ================================================================================== +# +# 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.schemas import ma +from trainingmgr.models import TrainingJob + +class TrainingJobSchema(ma.SQLAlchemyAutoSchema): + class Meta: + model = TrainingJob + include_relationships = True + load_instance = True \ No newline at end of file diff --git a/trainingmgr/trainingmgr_main.py b/trainingmgr/trainingmgr_main.py index 91ddc47..385d9ee 100644 --- a/trainingmgr/trainingmgr_main.py +++ b/trainingmgr/trainingmgr_main.py @@ -56,6 +56,7 @@ from trainingmgr.db.common_db_fun import get_data_extraction_in_progress_trainin get_field_of_given_version,get_all_jobs_latest_status_version, get_info_of_latest_version, \ get_feature_groups_db, get_feature_group_by_name_db, delete_feature_group_by_name, delete_trainingjob_version, change_field_value_by_version from trainingmgr.models import db, TrainingJob, FeatureGroup +from trainingmgr.schemas import ma, TrainingJobSchema , FeatureGroupSchema APP = Flask(__name__) TRAININGMGR_CONFIG_OBJ = None