From: subhash kumar singh Date: Mon, 9 Dec 2024 11:43:49 +0000 (+0000) Subject: Model discovery align with spec X-Git-Tag: 4.0.0~20 X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=commitdiff_plain;h=8ebd09a27ae8682ea35e9b83cf4c1c72d3889167;p=aiml-fw%2Fawmf%2Fmodelmgmtservice.git Model discovery align with spec Changes to align model discovery with specification. Change-Id: Ib782f15e2b88cf7ab22861fa90747bbac4d79ac3 Signed-off-by: subhash kumar singh --- diff --git a/apis/mmes_apis.go b/apis/mmes_apis.go index 2c15970..914495d 100644 --- a/apis/mmes_apis.go +++ b/apis/mmes_apis.go @@ -32,6 +32,11 @@ import ( "github.com/google/uuid" ) +const ( + MODELNAME = "model-name" + MODELVERSION = "model-version" +) + type MmeApiHandler struct { dbmgr core.DBMgr iDB db.IDB @@ -122,8 +127,8 @@ func (m *MmeApiHandler) GetModelInfo(cont *gin.Context) { queryParams := cont.Request.URL.Query() //to check only modelName and modelVersion can be passed. allowedParams := map[string]bool{ - "modelName": true, - "modelVersion": true, + MODELNAME: true, + MODELVERSION: true, } for key := range queryParams { @@ -135,10 +140,10 @@ func (m *MmeApiHandler) GetModelInfo(cont *gin.Context) { } } - modelName := cont.Query("modelName") - modelVersion := cont.Query("modelVersion") + modelName := cont.Query(MODELNAME) + modelVersion := cont.Query(MODELVERSION) - if modelName == "" { + if modelName == "" && modelVersion == "" { //return all modelinfo stored models, err := m.iDB.GetAll() @@ -166,9 +171,7 @@ func (m *MmeApiHandler) GetModelInfo(cont *gin.Context) { return } - cont.JSON(http.StatusOK, gin.H{ - "modelinfoList": modelInfos, - }) + cont.JSON(http.StatusOK, modelInfos) return } else { @@ -194,9 +197,8 @@ func (m *MmeApiHandler) GetModelInfo(cont *gin.Context) { return } - cont.JSON(http.StatusOK, gin.H{ - "modelinfo": modelInfo, - }) + response := []models.ModelRelatedInformation{*modelInfo} + cont.JSON(http.StatusOK, response) return } } diff --git a/apis_test/mmes_apis_test.go b/apis_test/mmes_apis_test.go index 4a28a82..159db44 100644 --- a/apis_test/mmes_apis_test.go +++ b/apis_test/mmes_apis_test.go @@ -139,7 +139,7 @@ func TestWhenSuccessGetModelInfoList(t *testing.T) { router := routers.InitRouter(handler) responseRecorder := httptest.NewRecorder() - req, _ := http.NewRequest("GET", "/getModelInfo", nil) + req, _ := http.NewRequest("GET", "/models", nil) router.ServeHTTP(responseRecorder, req) response := responseRecorder.Result() @@ -165,7 +165,7 @@ func TestWhenFailGetModelInfoList(t *testing.T) { router := routers.InitRouter(handler) responseRecorder := httptest.NewRecorder() - req, _ := http.NewRequest("GET", "/getModelInfo", nil) + req, _ := http.NewRequest("GET", "/models", nil) router.ServeHTTP(responseRecorder, req) response := responseRecorder.Result() diff --git a/request.http b/request.http index 987d10b..362217e 100644 --- a/request.http +++ b/request.http @@ -1,34 +1,35 @@ ### Note: update the vm ip in the host -@host = x.x.x.x:8082 +@host = x.x.x.x:32006 ### registraton -POST http://{{host}}/registerModel +POST http://{{host}}/model-registrations Content-Type: application/json { - "id": "12345", - "model-id": { - "modelName": "TestModel", + "modelId": { + "modelName": "TestModel1", "modelVersion": "v1.0" }, "description": "This is a test model.", - "meta-info": { - "metadata": { - "author": "John Doe" - } + "modelInformation": { + "metadata": { + "author": "John Doe" + }, + "inputDataType": "pdcp", + "outputDataType": "pdcp" } } ### Get All Models info -GET http://{{host}}/getModelInfo +GET http://{{host}}/models Content-Type: application/json ### Get all Models info by name -GET http://{{host}}/getModelInfo?modelName=TestModel +GET http://{{host}}/models?model-name=TestModel1 Content-Type: application/json ### Get all Models info by name and version -GET http://{{host}}/getModelInfo?modelName=TestModel&modelVersion=v1.0 +GET http://{{host}}/models?model-name=TestModel1&model-version=v1.0 Content-Type: application/json ### updated model diff --git a/routers/router.go b/routers/router.go index 8d4fa5f..6173967 100644 --- a/routers/router.go +++ b/routers/router.go @@ -32,7 +32,8 @@ func InitRouter(handler *apis.MmeApiHandler) *gin.Engine { r.PUT("/model-registrations/:modelRegistrationId", handler.UpdateModel) r.DELETE("/model-registrations/:modelRegistrationId", handler.DeleteModel) - r.GET("/getModelInfo", handler.GetModelInfo) + r.GET("/models", handler.GetModelInfo) + r.GET("/getModelInfo/:modelName", handler.GetModelInfoByName) r.POST("/uploadModel/:modelName", handler.UploadModel) r.GET("/downloadModel/:modelName/model.zip", handler.DownloadModel)