DB connection for service layer.
Note: Intially DB connection started using sqllite3 connection
later the connection would be updated to postgress.
Change-Id: I106fa3e8fdc16b762ed8203390a37375fef996e1
Signed-off-by: subhash kumar singh <subh.singh@samsung.com>
"os"
"gerrit.o-ran-sc.org/r/aiml-fw/awmf/modelmgmtservice/core"
+ "gerrit.o-ran-sc.org/r/aiml-fw/awmf/modelmgmtservice/db"
"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"
type MmeApiHandler struct {
dbmgr core.DBMgr
+ iDB db.IDB
}
-func NewMmeApiHandler(dbMgr core.DBMgr) *MmeApiHandler {
+func NewMmeApiHandler(dbMgr core.DBMgr, iDB db.IDB) *MmeApiHandler {
handler := &MmeApiHandler{
dbmgr: dbMgr,
+ iDB: iDB,
}
return handler
}
os.Setenv("LOG_FILE_NAME", "testing")
dbMgrMockInst := new(dbMgrMock)
dbMgrMockInst.On("CreateBucket", "test-model").Return(nil)
- handler := apis.NewMmeApiHandler(dbMgrMockInst)
+ handler := apis.NewMmeApiHandler(dbMgrMockInst, nil)
router := routers.InitRouter(handler)
w := httptest.NewRecorder()
req, _ := http.NewRequest("POST", "/registerModel", strings.NewReader(registerModelBody))
},
}, nil)
- handler := apis.NewMmeApiHandler(dbMgrMockInst)
+ handler := apis.NewMmeApiHandler(dbMgrMockInst, nil)
router := routers.InitRouter(handler)
responseRecorder := httptest.NewRecorder()
dbMgrMockInst := new(dbMgrMock)
dbMgrMockInst.On("ListBucket").Return([]core.Bucket{}, errors.New("Test: Fail GetModelInfoList"))
- handler := apis.NewMmeApiHandler(dbMgrMockInst)
+ handler := apis.NewMmeApiHandler(dbMgrMockInst, nil)
router := routers.InitRouter(handler)
responseRecorder := httptest.NewRecorder()
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/mattn/go-sqlite3 v1.14.22 // 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
golang.org/x/text v0.14.0 // indirect
google.golang.org/protobuf v1.30.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
+ gorm.io/driver/sqlite v1.5.6 // indirect
gorm.io/gorm v1.25.12 // indirect
)
github.com/leodido/go-urn v1.2.4/go.mod h1:7ZrI8mTSeBSHl/UaRyKQW1qZeMgak41ANeCNaVckg+4=
github.com/mattn/go-isatty v0.0.19 h1:JITubQf0MOLdlGRuRq+jtsDlekdYPia9ZFsB8h/APPA=
github.com/mattn/go-isatty v0.0.19/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
+github.com/mattn/go-sqlite3 v1.14.22 h1:2gZY6PC6kBnID23Tichd1K+Z0oS6nE/XwU+Vz/5o4kU=
+github.com/mattn/go-sqlite3 v1.14.22/go.mod h1:Uh1q+B4BYcTPb+yiD3kU8Ct7aC0hY9fxUwlHK0RXw+Y=
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg=
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
+gorm.io/driver/sqlite v1.5.6 h1:fO/X46qn5NUEEOZtnjJRWRzZMe8nqJiQ9E+0hi+hKQE=
+gorm.io/driver/sqlite v1.5.6/go.mod h1:U+J8craQU6Fzkcvu8oLeAQmi50TkwPEhHDEjQZXDah4=
gorm.io/gorm v1.25.12 h1:I0u8i2hWQItBq1WfE0o2+WuL9+8L21K9e2HHSTE/0f8=
gorm.io/gorm v1.25.12/go.mod h1:xh7N7RHfYlNc5EmcI/El95gXusucDrQnHXe0+CgWcLQ=
rsc.io/pdf v0.1.1/go.mod h1:n8OzWcQ6Sp37PL01nO98y4iUCRdTGarVfzxY20ICaU4=
"gerrit.o-ran-sc.org/r/aiml-fw/awmf/modelmgmtservice/apis"
"gerrit.o-ran-sc.org/r/aiml-fw/awmf/modelmgmtservice/core"
+ modelDB "gerrit.o-ran-sc.org/r/aiml-fw/awmf/modelmgmtservice/db"
"gerrit.o-ran-sc.org/r/aiml-fw/awmf/modelmgmtservice/logging"
+ "gerrit.o-ran-sc.org/r/aiml-fw/awmf/modelmgmtservice/models"
"gerrit.o-ran-sc.org/r/aiml-fw/awmf/modelmgmtservice/routers"
+ "gorm.io/driver/sqlite"
+ "gorm.io/gorm"
)
func main() {
+
+ // setup the database connection
+ db, err := gorm.Open(sqlite.Open("test.db"), &gorm.Config{})
+ if err != nil {
+ logging.ERROR("database not available")
+ os.Exit(-1)
+ }
+
+ // Auto migrate the scheme
+ db.AutoMigrate(&models.ModelInfo{})
+ repo := modelDB.NewModelInfoRepository(db)
+
router := routers.InitRouter(
apis.NewMmeApiHandler(
core.GetDBManagerInstance(),
+ repo,
))
server := http.Server{
Addr: os.Getenv("MMES_URL"),