TM module API fixes 71/13871/3
authorMonosij Ghosh <mono.ghosh@samsung.com>
Fri, 13 Dec 2024 13:02:39 +0000 (18:32 +0530)
committerMonosij Ghosh <mono.ghosh@samsung.com>
Mon, 16 Dec 2024 11:12:05 +0000 (16:42 +0530)
fixes for training job steps status and delete API

Change-Id: I71916022f7235e720b1ce37e3f8ebf36f44d2aa5
Signed-off-by: Monosij Ghosh <mono.ghosh@samsung.com>
request.http
trainingmgr/service/training_job_service.py
trainingmgr/trainingmgr_main.py

index ca5837e..48242c9 100644 (file)
@@ -88,7 +88,7 @@ Content-Type: application/json
 
 {
     "modelId":{
-        "modelname": "model7",
+        "modelname": "modeltest7",
         "modelversion": "1"
     },
     "model_location": "",
@@ -152,7 +152,15 @@ Content-Type: application/json
 POST http://{{base}}/training-jobs/12/training
 Content-Type: application/json
 
-
 ### Get training job status by ID
 GET http://{{base}}/training-jobs/12/status
 Content-Type: application/json
+
+### Get training job details by training job ID
+GET http://{{base}}/training-jobs/18
+Content-Type: application/json
+
+### Delete training job by training job ID
+DELETE http://{{base}}/training-jobs/41
+Content-Type: application/json
+
index d430f25..72764d0 100644 (file)
@@ -82,29 +82,31 @@ def delete_training_job(training_job_id : int):
     try:
         # Signal Deletion in Progress
         tj = get_trainingjob(training_job_id)
-        # print("Run Id = ", tj.run_id, "   --  ", tj.run_id is None)
         change_field_value(training_job_id, "deletion_in_progress", True)
-        # isDeleted = True
+        steps_state =  json.loads(tj.steps_state.states)
+        overall_status = get_one_word_status(steps_state)
+        
+        if overall_status == States.IN_PROGRESS.name:
+            step_in_progress_state = get_step_in_progress_state(steps_state)
+            if step_in_progress_state == Steps.DATA_EXTRACTION:
+                pass
+                # TODO: Remove the job from DATAEXTRACTION_JOBS_CACHE to signal not to check its status
+                # with LOCK:
+                #     DATAEXTRACTION_JOBS_CACHE.pop(trainingjob_name)
+            elif (step_in_progress_state == Steps.TRAINING or (step_in_progress_state == Steps.DATA_EXTRACTION_AND_TRAINING and tj.run_id is not None)):
+                # Signal the Kf-Adapter to terminate the 
+                response = terminate_training_service(tj.run_id)
+                LOGGER.debug("Deletion-Response : " + response)
+
         isDeleted = delete_trainingjob_by_id(id=training_job_id)
         if isDeleted:
-            steps_state =  json.loads(tj.steps_state.states)
-            overall_status = get_one_word_status(steps_state)
-            if overall_status == States.IN_PROGRESS.name:
-                step_in_progress_state = get_step_in_progress_state(steps_state)
-                if step_in_progress_state == Steps.DATA_EXTRACTION:
-                    pass
-                    # TODO: Remove the job from DATAEXTRACTION_JOBS_CACHE to signal not to check its status
-                    # with LOCK:
-                    #     DATAEXTRACTION_JOBS_CACHE.pop(trainingjob_name)
-                elif (step_in_progress_state == Steps.TRAINING or (step_in_progress_state == Steps.DATA_EXTRACTION_AND_TRAINING and tj.run_id is not None)):
-                    # Signal the Kf-Adapter to terminate the training
-                    response = terminate_training_service(tj.run_id)
-                    print("Deletion-Response : ", response)  
             return True
         else:
             return False
     except Exception as err :
         raise DBException(f"delete_trainining_job failed with exception : {str(err)}")
+
+
 def get_trainingjob_by_modelId(model_id):
     try:
         trainingjob = get_trainingjob_by_modelId_db(model_id)
@@ -167,4 +169,4 @@ def update_artifact_version(trainingjob_id, artifact_version : str, level : str)
         changeartifact(trainingjob_id, new_artifact_version)
         return f'{major}.{minor}.{patch}'
     except Exception as err:
-        raise TMException(f"failed to update_artifact_version with exception : {str(err)}")
\ No newline at end of file
+        raise TMException(f"failed to update_artifact_version with exception : {str(err)}")
index 7474876..2c92cfb 100644 (file)
@@ -202,11 +202,14 @@ def data_extraction_notification():
             change_status_tj(trainingjob.id,
                             Steps.DATA_EXTRACTION_AND_TRAINING.name,
                             States.FINISHED.name)
+            LOGGER.debug("DATA_EXTRACTION_AND_TRAINING step set to FINISHED for training job " + trainingjob.id)
             change_status_tj(trainingjob.id,
                             Steps.TRAINING.name,
                             States.IN_PROGRESS.name)
-            change_update_field_value(trainingjob,
-                                        "run_id", json_data["run_id"])
+            LOGGER.debug("TRAINING step set to IN_PROGRESS for training job " + trainingjob.id)
+            change_update_field_value(trainingjob.id,
+                                     "run_id", 
+                                     json_data["run_id"])
             # notification_rapp(trainingjob, TRAININGMGR_CONFIG_OBJ)
         else:
             raise TMException("KF Adapter- run_status in not scheduled")