init
This commit is contained in:
parent
85fc43368b
commit
1dfff4635e
@ -26,7 +26,7 @@ var (
|
|||||||
ResourceMap map[string]interface{}
|
ResourceMap map[string]interface{}
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func Init(collections []string) {
|
||||||
// var baseConfig string
|
// var baseConfig string
|
||||||
var err error
|
var err error
|
||||||
var conf map[string]string
|
var conf map[string]string
|
||||||
@ -52,7 +52,7 @@ func init() {
|
|||||||
createClient(lib.GetConfig().MongoURL)
|
createClient(lib.GetConfig().MongoURL)
|
||||||
|
|
||||||
lib.Logger.Info().Msg("Connecting mongo client to db " + DBname)
|
lib.Logger.Info().Msg("Connecting mongo client to db " + DBname)
|
||||||
prepareDB(lib.GetConfig().DCNAME, lib.GetConfig().DBPOINT)
|
prepareDB(collections, lib.GetConfig().DCNAME, lib.GetConfig().DBPOINT)
|
||||||
|
|
||||||
lib.Logger.Info().Msg("Database is READY")
|
lib.Logger.Info().Msg("Database is READY")
|
||||||
|
|
||||||
@ -88,13 +88,10 @@ func createClient(MongoURL string) {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func prepareDB(dc_name string, db_point string) {
|
func prepareDB(list_collection []string, dc_name string, db_point string) {
|
||||||
var err error
|
var err error
|
||||||
DBname := dc_name + "-" + db_point
|
DBname := dc_name + "-" + db_point
|
||||||
mngoDB = mngoClient.Database(DBname)
|
mngoDB = mngoClient.Database(DBname)
|
||||||
|
|
||||||
list_collection := [...]string{"data", "processing", "storage", "datacenter", "workspace", "schedule", "workflow"}
|
|
||||||
|
|
||||||
existingCollections, err = mngoDB.ListCollectionNames(MngoCtx, bson.D{})
|
existingCollections, err = mngoDB.ListCollectionNames(MngoCtx, bson.D{})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
lib.Logger.Fatal().Msg("Error contacting MongoDB\n" + err.Error())
|
lib.Logger.Fatal().Msg("Error contacting MongoDB\n" + err.Error())
|
||||||
|
@ -2,6 +2,7 @@ package models
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
oclib "oc-lib"
|
oclib "oc-lib"
|
||||||
|
"oc-lib/dbs/mongo"
|
||||||
r "oc-lib/models/resources"
|
r "oc-lib/models/resources"
|
||||||
d "oc-lib/models/resources/data"
|
d "oc-lib/models/resources/data"
|
||||||
dc "oc-lib/models/resources/datacenter"
|
dc "oc-lib/models/resources/datacenter"
|
||||||
@ -27,3 +28,11 @@ func Model(model string) utils.DBObject {
|
|||||||
log.Error().Msg("Can't find model " + model + ".")
|
log.Error().Msg("Can't find model " + model + ".")
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func Init() {
|
||||||
|
dbs := []string{}
|
||||||
|
for db := range models {
|
||||||
|
dbs = append(dbs, db)
|
||||||
|
}
|
||||||
|
mongo.Init(dbs)
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user