Add Model-Registration Check during Upload-Model 67/14967/8
authorashishj1729 <jain.ashish@samsung.com>
Mon, 22 Sep 2025 19:07:29 +0000 (00:37 +0530)
committerAshish Jain <jain.ashish@samsung.com>
Tue, 30 Sep 2025 06:14:51 +0000 (06:14 +0000)
Whenever an external model is uploaded, registration of model will be checked, and if model is NOT found to be registered, user is prompted to register the model first.

Issue-id: AIMLFW-261
Change-Id: I79b51f0f455af441fccc8894ed6bd231e98c5af5
Signed-off-by: ashishj1729 <jain.ashish@samsung.com>
apis/mmes_apis.go

index af9bd21..38bce11 100644 (file)
@@ -23,6 +23,7 @@ import (
        "io"
        "net/http"
        "os"
+       "strconv"
        "strings"
 
        "gerrit.o-ran-sc.org/r/aiml-fw/awmf/modelmgmtservice/core"
@@ -250,13 +251,40 @@ func (m *MmeApiHandler) GetModelInfoByName(cont *gin.Context) {
        })
 }
 
-// API to upload the trained model in zip format
+/*
+* The following API uploads the trained model in zip-format to the provided modelId (modelName, modelVersion, artifactVersion)
+* Note: Model MUST be registered first, and then should be uploaded
+ */
 func (m *MmeApiHandler) UploadModel(cont *gin.Context) {
        logging.INFO("Uploading model API ...")
        modelName := cont.Param("modelName")
        modelVersion := cont.Param("modelVersion")
        artifactVersion := cont.Param("artifactVersion")
 
+       // Confirm if Model with Given ModelId: (ModelName and ModelVersion) is Registered or not:
+       modelInfo, err := m.iDB.GetModelInfoByNameAndVer(modelName, modelVersion)
+       if err != nil {
+               statusCode := http.StatusInternalServerError
+               logging.ERROR("Error occurred while getting models: " + strconv.Itoa(statusCode))
+               cont.JSON(statusCode, models.ProblemDetail{
+                       Status: statusCode,
+                       Title:  "Internal Server Error",
+                       Detail: fmt.Sprintf("Can't fetch model with modelName : %s & modelVersion : %s due to , %s", modelName, modelVersion, err.Error()),
+               })
+               return
+       }
+
+       if modelInfo.ModelId.ModelName != modelName && modelInfo.ModelId.ModelVersion != modelVersion {
+               statusCode := http.StatusNotFound
+               logging.ERROR("Record not found, send status code: " + strconv.Itoa(statusCode))
+               cont.JSON(statusCode, models.ProblemDetail{
+                       Status: statusCode,
+                       Title:  "Not Found",
+                       Detail: fmt.Sprintf("ModelName: %s and modelVersion: %s is not registered, Kindly register it first!", modelName, modelVersion),
+               })
+               return
+       }
+
        modelKey := fmt.Sprintf("%s_%s_%s", modelName, modelVersion, artifactVersion)
        exportBucket := strings.ToLower(modelName)
        //TODO convert multipart.FileHeader to []byte