Refactor models to separate folder 03/13503/2
authorsubhash kumar singh <subh.singh@samsung.com>
Mon, 30 Sep 2024 14:15:50 +0000 (14:15 +0000)
committersubhash kumar singh <subh.singh@samsung.com>
Mon, 7 Oct 2024 07:20:47 +0000 (07:20 +0000)
Refactor models to separate folder.

Change-Id: I5d3611b2293989589d9513449727409d2e07872a
Signed-off-by: subhash kumar singh <subh.singh@samsung.com>
apis/mmes_apis.go
apis_test/mmes_apis_test.go
go.mod
models/modelInfo.go [new file with mode: 0644]

index 60cf486..3b9f383 100644 (file)
@@ -25,35 +25,11 @@ import (
 
        "gerrit.o-ran-sc.org/r/aiml-fw/awmf/modelmgmtservice/core"
        "gerrit.o-ran-sc.org/r/aiml-fw/awmf/modelmgmtservice/logging"
+       "gerrit.o-ran-sc.org/r/aiml-fw/awmf/modelmgmtservice/models"
        "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 {
-       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"`
-}
-
 type MmeApiHandler struct {
        dbmgr core.DBMgr
 }
@@ -70,7 +46,7 @@ func (m *MmeApiHandler) RegisterModel(cont *gin.Context) {
        logging.INFO("Creating model...")
        bodyBytes, _ := io.ReadAll(cont.Request.Body)
 
-       var modelInfo ModelInfo
+       var modelInfo models.ModelInfo
        //Need to unmarshal JSON to Struct, to access request
        //data such as model name, rapp id etc
        err := json.Unmarshal(bodyBytes, &modelInfo)
@@ -115,9 +91,9 @@ func (m *MmeApiHandler) GetModelInfo(cont *gin.Context) {
                return
        }
 
-       modelInfoListResp := []ModelInfoResponse{}
+       modelInfoListResp := []models.ModelInfoResponse{}
        for _, bucket := range bucketList {
-               modelInfoListResp = append(modelInfoListResp, ModelInfoResponse{
+               modelInfoListResp = append(modelInfoListResp, models.ModelInfoResponse{
                        Name: bucket.Name,
                        Data: string(bucket.Object),
                })
@@ -137,7 +113,7 @@ func (m *MmeApiHandler) GetModelInfoByName(cont *gin.Context) {
        modelName := cont.Param("modelName")
 
        bucketObj := m.dbmgr.GetBucketObject(modelName+os.Getenv("INFO_FILE_POSTFIX"), modelName)
-       modelInfoListResp := ModelInfoResponse{
+       modelInfoListResp := models.ModelInfoResponse{
                Name: modelName,
                Data: string(bucketObj),
        }
index 7276b40..8116367 100644 (file)
@@ -29,6 +29,7 @@ import (
 
        "gerrit.o-ran-sc.org/r/aiml-fw/awmf/modelmgmtservice/apis"
        "gerrit.o-ran-sc.org/r/aiml-fw/awmf/modelmgmtservice/core"
+       "gerrit.o-ran-sc.org/r/aiml-fw/awmf/modelmgmtservice/models"
        "gerrit.o-ran-sc.org/r/aiml-fw/awmf/modelmgmtservice/routers"
        "github.com/stretchr/testify/assert"
        "github.com/stretchr/testify/mock"
@@ -36,12 +37,12 @@ import (
 
 var registerModelBody = `{
        "id" : "id", 
-       "model-id": {
+       "modelId": {
                "modelName": "test-model",
                "modelVersion":"1"
        },
        "description": "testing",
-       "meta-info": {
+       "metaInfo": {
                "metadata": {
                        "author":"tester"
                }
@@ -102,8 +103,8 @@ func TestWhenSuccessGetModelInfoList(t *testing.T) {
        body, _ := io.ReadAll(response.Body)
 
        var modelInfoListResp struct {
-               Code    int                      `json:"code"`
-               Message []apis.ModelInfoResponse `json:"message"`
+               Code    int                        `json:"code"`
+               Message []models.ModelInfoResponse `json:"message"`
        }
        json.Unmarshal(body, &modelInfoListResp)
 
@@ -131,8 +132,8 @@ func TestWhenFailGetModelInfoList(t *testing.T) {
        body, _ := io.ReadAll(response.Body)
 
        var modelInfoListResp struct {
-               Code    int                      `json:"code"`
-               Message []apis.ModelInfoResponse `json:"message"`
+               Code    int                        `json:"code"`
+               Message []models.ModelInfoResponse `json:"message"`
        }
        json.Unmarshal(body, &modelInfoListResp)
 
diff --git a/go.mod b/go.mod
index 173e66a..3fd1e8a 100644 (file)
--- a/go.mod
+++ b/go.mod
@@ -5,6 +5,7 @@ go 1.21.3
 require (
        github.com/aws/aws-sdk-go v1.47.3
        github.com/gin-gonic/gin v1.9.1
+       github.com/google/uuid v1.6.0
        github.com/stretchr/testify v1.8.3
 )
 
@@ -23,7 +24,6 @@ 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/models/modelInfo.go b/models/modelInfo.go
new file mode 100644 (file)
index 0000000..7ea86ba
--- /dev/null
@@ -0,0 +1,43 @@
+/*
+==================================================================================
+Copyright (c) 2024 Samsung Electronics Co., Ltd. All Rights Reserved.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+==================================================================================
+*/
+
+package models
+
+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 {
+       Id          string    `json:"id"`
+       ModelId     ModelID   `json:"modelId,omitempty"`
+       Description string    `json:"description"`
+       ModelSpec   ModelSpec `json:"metaInfo"`
+}
+
+type ModelInfoResponse struct {
+       Name string `json:"name"`
+       Data string `json:"data"`
+}