diff --git a/dbs/mongo/mongo.go b/dbs/mongo/mongo.go index 6b3340a..628695a 100644 --- a/dbs/mongo/mongo.go +++ b/dbs/mongo/mongo.go @@ -26,7 +26,7 @@ var ( ResourceMap map[string]interface{} ) -func init() { +func Init(collections []string) { // var baseConfig string var err error var conf map[string]string @@ -52,7 +52,7 @@ func init() { createClient(lib.GetConfig().MongoURL) 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") @@ -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 DBname := dc_name + "-" + db_point mngoDB = mngoClient.Database(DBname) - - list_collection := [...]string{"data", "processing", "storage", "datacenter", "workspace", "schedule", "workflow"} - existingCollections, err = mngoDB.ListCollectionNames(MngoCtx, bson.D{}) if err != nil { lib.Logger.Fatal().Msg("Error contacting MongoDB\n" + err.Error()) diff --git a/models/models.go b/models/models.go index 069e00d..39a69a8 100644 --- a/models/models.go +++ b/models/models.go @@ -2,6 +2,7 @@ package models import ( oclib "oc-lib" + "oc-lib/dbs/mongo" r "oc-lib/models/resources" d "oc-lib/models/resources/data" dc "oc-lib/models/resources/datacenter" @@ -27,3 +28,11 @@ func Model(model string) utils.DBObject { log.Error().Msg("Can't find model " + model + ".") return nil } + +func Init() { + dbs := []string{} + for db := range models { + dbs = append(dbs, db) + } + mongo.Init(dbs) +}