From 488a44b70989fbad586e54046ea61fd839c14e29 Mon Sep 17 00:00:00 2001 From: ashishj1729 Date: Tue, 23 Sep 2025 00:37:29 +0530 Subject: [PATCH] Add Model-Registration Check during Upload-Model 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 --- apis/mmes_apis.go | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/apis/mmes_apis.go b/apis/mmes_apis.go index af9bd21..38bce11 100644 --- a/apis/mmes_apis.go +++ b/apis/mmes_apis.go @@ -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 -- 2.16.6