From: rajdeep11 Date: Wed, 6 Nov 2024 19:26:09 +0000 (+0530) Subject: adding steps state model X-Git-Tag: 3.0.0~41^2 X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=commitdiff_plain;h=0dbb2c6d75a4f4bb1e5b1bf21fba0abb4a91e9e0;p=aiml-fw%2Fawmf%2Ftm.git adding steps state model Change-Id: Id8e5b2f000941a1f3839f1fb9cca1c42bdfcf9c7 Signed-off-by: rajdeep11 --- diff --git a/tests/test_tm_apis.py b/tests/test_tm_apis.py index 707001d..320f7f0 100644 --- a/tests/test_tm_apis.py +++ b/tests/test_tm_apis.py @@ -18,7 +18,7 @@ import json import requests from unittest import mock -from mock import patch +from mock import patch, MagicMock import pytest import flask from requests.models import Response @@ -296,13 +296,15 @@ class Test_get_trainingjob_by_name_version: } } - + mock_steps_state = MagicMock() + mock_steps_state.states = {"step1":"completed"} + return TrainingJob( trainingjob_name="test_job", training_config = json.dumps(training_config), creation_time=creation_time, run_id="test_run_id", - steps_state=json.dumps({"step1": "completed"}), + steps_state=mock_steps_state, updation_time=updation_time, version=1, model_url="http://test.model.url", diff --git a/trainingmgr/models/__init__.py b/trainingmgr/models/__init__.py index aa18ff7..984f025 100644 --- a/trainingmgr/models/__init__.py +++ b/trainingmgr/models/__init__.py @@ -21,5 +21,6 @@ db = SQLAlchemy() from trainingmgr.models.trainingjob import TrainingJob from trainingmgr.models.featuregroup import FeatureGroup +from trainingmgr.models.steps_state import TrainingJobStatus -__all_ = ['TrainingJob', 'FeatureGroup'] \ No newline at end of file +__all_ = ['TrainingJob', 'FeatureGroup', 'TrainingJobStatus'] \ No newline at end of file diff --git a/trainingmgr/models/steps_state.py b/trainingmgr/models/steps_state.py new file mode 100644 index 0000000..e5a51d9 --- /dev/null +++ b/trainingmgr/models/steps_state.py @@ -0,0 +1,33 @@ +# ================================================================================== +# +# 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 sqlalchemy import Integer, String, Column, DateTime +from sqlalchemy.sql import func +from sqlalchemy.orm import relationship +from . import db + +class TrainingJobStatus(db.Model): + __tablename__ = 'training_job_status_table' + + id = Column(Integer, primary_key=True) + states = Column(String, nullable=False) + creation_time = Column(DateTime(timezone=False), server_default=func.now(),nullable=False) + updation_time = Column(DateTime(timezone=False),onupdate=func.now() ,nullable=True) + + # Establish a relationship to TrainingJob + trainingjobs = relationship("TrainingJob", back_populates="steps_state") \ No newline at end of file diff --git a/trainingmgr/models/trainingjob.py b/trainingmgr/models/trainingjob.py index 64a0535..db2e051 100644 --- a/trainingmgr/models/trainingjob.py +++ b/trainingmgr/models/trainingjob.py @@ -18,22 +18,27 @@ from . import db from datetime import datetime from sqlalchemy.sql import func +from sqlalchemy import Integer, ForeignKey, String, DateTime, Column, Boolean +from sqlalchemy.orm import relationship class TrainingJob(db.Model): __tablename__ = "trainingjob_info_table" - id = db.Column(db.Integer, primary_key=True) - trainingjob_name= db.Column(db.String(128), nullable=False) - run_id = db.Column(db.String(1000), nullable=True) - steps_state = db.Column(db.String(1000), nullable=True) - creation_time = db.Column(db.DateTime(timezone=False), server_default=func.now(),nullable=False) - updation_time = db.Column(db.DateTime(timezone=False),onupdate=func.now() ,nullable=True) - version = db.Column(db.Integer, nullable=True) - deletion_in_progress = db.Column(db.Boolean, nullable=True) - training_config = db.Column(db.String(5000), nullable=False) - model_url = db.Column(db.String(1000), nullable=True) - notification_url = db.Column(db.String(1000), nullable=True) - model_name = db.Column(db.String(128), nullable=True) - model_info = db.Column(db.String(1000), nullable=True) + id = Column(Integer, primary_key=True) + trainingjob_name= Column(String(128), nullable=False) + run_id = Column(String(1000), nullable=True) + steps_state_id = Column(Integer, ForeignKey('training_job_status_table.id'), nullable=True) + creation_time = Column(DateTime(timezone=False), server_default=func.now(),nullable=False) + updation_time = Column(DateTime(timezone=False),onupdate=func.now() ,nullable=True) + version = Column(Integer, nullable=True) + deletion_in_progress = Column(Boolean, nullable=True) + training_config = Column(String(5000), nullable=False) + model_url = Column(String(1000), nullable=True) + notification_url = Column(String(1000), nullable=True) + model_name = Column(String(128), nullable=True) + model_info = Column(String(1000), nullable=True) + + #defineing relationships + steps_state = relationship("TrainingJobStatus", back_populates="trainingjobs") def __repr__(self): return f'' \ No newline at end of file diff --git a/trainingmgr/trainingmgr_main.py b/trainingmgr/trainingmgr_main.py index bd8450e..6e18acc 100644 --- a/trainingmgr/trainingmgr_main.py +++ b/trainingmgr/trainingmgr_main.py @@ -182,7 +182,7 @@ def get_trainingjob_by_name_version(trainingjob_name, version): # "query_filter": trainingjob.query_filter, "creation_time": str(trainingjob.creation_time), "run_id": trainingjob.run_id, - "steps_state": json.loads(trainingjob.steps_state), + "steps_state": trainingjob.steps_state.states , "updation_time": str(trainingjob.updation_time), "version": trainingjob.version, # "enable_versioning": trainingjob.enable_versioning,