adding steps state model 34/13734/7
authorrajdeep11 <rajdeep.sin@samsung.com>
Wed, 6 Nov 2024 19:26:09 +0000 (00:56 +0530)
committerrajdeep11 <rajdeep.sin@samsung.com>
Tue, 19 Nov 2024 05:43:17 +0000 (11:13 +0530)
Change-Id: Id8e5b2f000941a1f3839f1fb9cca1c42bdfcf9c7
Signed-off-by: rajdeep11 <rajdeep.sin@samsung.com>
tests/test_tm_apis.py
trainingmgr/models/__init__.py
trainingmgr/models/steps_state.py [new file with mode: 0644]
trainingmgr/models/trainingjob.py
trainingmgr/trainingmgr_main.py

index 707001d..320f7f0 100644 (file)
@@ -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",
index aa18ff7..984f025 100644 (file)
@@ -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 (file)
index 0000000..e5a51d9
--- /dev/null
@@ -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
index 64a0535..db2e051 100644 (file)
 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'<Trainingjob {self.trainingjob_name}>'
\ No newline at end of file
index bd8450e..6e18acc 100644 (file)
@@ -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,