changes in the modelinfo by adding model id 35/13435/15
authorrajdeep11 <rajdeep.sin@samsung.com>
Wed, 25 Sep 2024 07:31:21 +0000 (13:01 +0530)
committerrajdeep11 <rajdeep.sin@samsung.com>
Mon, 30 Sep 2024 12:22:32 +0000 (17:52 +0530)
Change-Id: I619a13069a8d209b8c9ab3c5762d65a206230ddc
Signed-off-by: rajdeep11 <rajdeep.sin@samsung.com>
apis/mmes_apis.go
apis_test/mmes_apis_test.go
go.mod
go.sum

index a9c7aaf..60cf486 100644 (file)
@@ -26,14 +26,29 @@ import (
        "gerrit.o-ran-sc.org/r/aiml-fw/awmf/modelmgmtservice/core"
        "gerrit.o-ran-sc.org/r/aiml-fw/awmf/modelmgmtservice/logging"
        "github.com/gin-gonic/gin"
+       "github.com/google/uuid"
 )
 
+type Metadata struct {
+       Author string `json:"author"`
+}
+
+type ModelSpec struct {
+       Metadata Metadata `json:"metadata"`
+}
+type ModelID struct {
+       ModelName string `json:"modelName"`
+       modelVersion string `json:"modelVersion"`
+}  
+
 type ModelInfo struct {
-       ModelName string                 `json:"model-name"`
-       RAppId    string                 `json:"rapp-id"`
-       Metainfo  map[string]interface{} `json:"meta-info"`
+       Id string `json:"id"`
+       ModelId ModelID `json:"model-id,omitempty"`
+       Description string `json:"description"`
+       ModelSpec ModelSpec `json:"meta-info"`
 }
 
+
 type ModelInfoResponse struct {
        Name string `json:"name"`
        Data string `json:"data"`
@@ -51,8 +66,6 @@ func NewMmeApiHandler(dbMgr core.DBMgr) *MmeApiHandler {
 }
 
 func (m *MmeApiHandler) RegisterModel(cont *gin.Context) {
-       var returnCode int = http.StatusCreated
-       var responseMsg string = "Model registered successfully"
 
        logging.INFO("Creating model...")
        bodyBytes, _ := io.ReadAll(cont.Request.Body)
@@ -61,26 +74,27 @@ func (m *MmeApiHandler) RegisterModel(cont *gin.Context) {
        //Need to unmarshal JSON to Struct, to access request
        //data such as model name, rapp id etc
        err := json.Unmarshal(bodyBytes, &modelInfo)
-       if err != nil || modelInfo.ModelName == "" {
+       if err != nil || modelInfo.ModelId.ModelName == "" {
                logging.ERROR("Error in unmarshalling")
                cont.JSON(http.StatusBadRequest, gin.H{
                        "code":    http.StatusBadRequest,
                        "message": string("Can not parse input data, provide mandatory details"),
                })
        } else {
-               logging.INFO(modelInfo.ModelName, modelInfo.RAppId, modelInfo.Metainfo)
+               id := uuid.New()
+               modelInfo.Id = id.String()
                modelInfoBytes, _ := json.Marshal(modelInfo)
-
-               err := m.dbmgr.CreateBucket(modelInfo.ModelName)
+               err := m.dbmgr.CreateBucket(modelInfo.ModelId.ModelName)
                if err == nil {
-                       m.dbmgr.UploadFile(modelInfoBytes, modelInfo.ModelName+os.Getenv("INFO_FILE_POSTFIX"), modelInfo.ModelName)
+                       m.dbmgr.UploadFile(modelInfoBytes, modelInfo.ModelId.ModelName+os.Getenv("INFO_FILE_POSTFIX"), modelInfo.ModelId.ModelName)
                } else {
-                       returnCode = http.StatusInternalServerError
-                       responseMsg = err.Error()
+                       cont.JSON(http.StatusInternalServerError, gin.H{
+                               "code":    http.StatusInternalServerError,
+                               "message": err.Error(),
+                       })
                }
-               cont.JSON(returnCode, gin.H{
-                       "code":    returnCode,
-                       "message": responseMsg,
+               cont.JSON(http.StatusCreated, gin.H{
+                       "modelinfo": modelInfoBytes,
                })
        }
 }
index c8db6ee..7276b40 100644 (file)
@@ -35,10 +35,16 @@ import (
 )
 
 var registerModelBody = `{
-       "model-name": "test-model",
-       "rapp-id": "1234",
+       "id" : "id", 
+       "model-id": {
+               "modelName": "test-model",
+               "modelVersion":"1"
+       },
+       "description": "testing",
        "meta-info": {
-               "a": "b"
+               "metadata": {
+                       "author":"tester"
+               }
        }
 }`
 
diff --git a/go.mod b/go.mod
index 7886fda..173e66a 100644 (file)
--- a/go.mod
+++ b/go.mod
@@ -23,6 +23,7 @@ require (
        github.com/klauspost/cpuid/v2 v2.2.4 // indirect
        github.com/leodido/go-urn v1.2.4 // indirect
        github.com/mattn/go-isatty v0.0.19 // indirect
+    github.com/google/uuid v1.6.0 // indirect
        github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
        github.com/modern-go/reflect2 v1.0.2 // indirect
        github.com/pelletier/go-toml/v2 v2.0.8 // indirect
diff --git a/go.sum b/go.sum
index 87f381e..ad98624 100644 (file)
--- a/go.sum
+++ b/go.sum
@@ -58,6 +58,8 @@ github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpE
 github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
 github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
 github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
+github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
+github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
 github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
 github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
 github.com/stretchr/testify v1.8.2/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=