Model discovery align with spec 41/13841/1
authorsubhash kumar singh <subh.singh@samsung.com>
Mon, 9 Dec 2024 11:43:49 +0000 (11:43 +0000)
committersubhash kumar singh <subh.singh@samsung.com>
Mon, 9 Dec 2024 11:43:49 +0000 (11:43 +0000)
Changes to align model discovery with specification.

Change-Id: Ib782f15e2b88cf7ab22861fa90747bbac4d79ac3
Signed-off-by: subhash kumar singh <subh.singh@samsung.com>
apis/mmes_apis.go
apis_test/mmes_apis_test.go
request.http
routers/router.go

index 2c15970..914495d 100644 (file)
@@ -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
                }
        }
index 4a28a82..159db44 100644 (file)
@@ -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()
index 987d10b..362217e 100644 (file)
@@ -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
index 8d4fa5f..6173967 100644 (file)
@@ -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)