From 5d2089979ce9ee99e7b3af690704399e4f2db721 Mon Sep 17 00:00:00 2001 From: ionutboangiu Date: Wed, 2 Mar 2022 15:04:28 +0200 Subject: [PATCH] Remove tenant from arguments for config storage functions --- engine/datadbmock.go | 6 +++--- engine/storage_interface.go | 6 +++--- engine/storage_internal_datadb.go | 16 ++++++++-------- engine/storage_it_test.go | 30 +++++++++++++++--------------- engine/storage_mongo_datadb.go | 10 +++------- engine/storage_redis.go | 6 +++--- 6 files changed, 35 insertions(+), 39 deletions(-) diff --git a/engine/datadbmock.go b/engine/datadbmock.go index 08f1bdd71..a36d2b71c 100644 --- a/engine/datadbmock.go +++ b/engine/datadbmock.go @@ -447,14 +447,14 @@ func (dbM *DataDBMock) RemoveRatingProfileDrv(string) error { return utils.ErrNotImplemented } -func (dbM *DataDBMock) GetConfigSectionsDrv(ctx *context.Context, tenant, nodeID string, sectionIDs []string) (map[string][]byte, error) { +func (dbM *DataDBMock) GetConfigSectionsDrv(ctx *context.Context, nodeID string, sectionIDs []string) (map[string][]byte, error) { return nil, utils.ErrNotImplemented } -func (dbM *DataDBMock) SetConfigSectionsDrv(ctx *context.Context, tenant, nodeID string, sectionsData map[string][]byte) error { +func (dbM *DataDBMock) SetConfigSectionsDrv(ctx *context.Context, nodeID string, sectionsData map[string][]byte) error { return utils.ErrNotImplemented } -func (dbM *DataDBMock) RemoveConfigSectionsDrv(ctx *context.Context, tenant, nodeID string, sectionIDs []string) error { +func (dbM *DataDBMock) RemoveConfigSectionsDrv(ctx *context.Context, nodeID string, sectionIDs []string) error { return utils.ErrNotImplemented } diff --git a/engine/storage_interface.go b/engine/storage_interface.go index 10076dbe2..e4ef88c87 100644 --- a/engine/storage_interface.go +++ b/engine/storage_interface.go @@ -95,9 +95,9 @@ type DataDB interface { GetAccountDrv(*context.Context, string, string) (*utils.Account, error) SetAccountDrv(ctx *context.Context, profile *utils.Account) error RemoveAccountDrv(*context.Context, string, string) error - GetConfigSectionsDrv(*context.Context, string, string, []string) (map[string][]byte, error) - SetConfigSectionsDrv(*context.Context, string, string, map[string][]byte) error - RemoveConfigSectionsDrv(*context.Context, string, string, []string) error + GetConfigSectionsDrv(*context.Context, string, []string) (map[string][]byte, error) + SetConfigSectionsDrv(*context.Context, string, map[string][]byte) error + RemoveConfigSectionsDrv(*context.Context, string, []string) error } // DataDBDriver used as a DataDB but also as a ConfigProvider diff --git a/engine/storage_internal_datadb.go b/engine/storage_internal_datadb.go index 452d9b05f..227067fee 100644 --- a/engine/storage_internal_datadb.go +++ b/engine/storage_internal_datadb.go @@ -652,13 +652,13 @@ func (iDB *InternalDB) RemoveAccountDrv(_ *context.Context, tenant, id string) ( return } -func (iDB *InternalDB) GetConfigSectionsDrv(ctx *context.Context, tenant, nodeID string, sectionIDs []string) (sectionMap map[string][]byte, err error) { +func (iDB *InternalDB) GetConfigSectionsDrv(ctx *context.Context, nodeID string, sectionIDs []string) (sectionMap map[string][]byte, err error) { sectionMap = make(map[string][]byte) for _, sectionID := range sectionIDs { - x, ok := iDB.db.Get(utils.CacheConfig, utils.ConcatenatedKey(tenant, nodeID, sectionID)) + x, ok := iDB.db.Get(utils.CacheConfig, utils.ConcatenatedKey(nodeID, sectionID)) if !ok || x == nil { - utils.Logger.Warning(fmt.Sprintf("<%+v> Could not find any data for section <%+v>", - utils.ConcatenatedKey(tenant, nodeID), sectionID)) + utils.Logger.Warning(fmt.Sprintf("CGRateS<%+v> Could not find any data for section <%+v>", + nodeID, sectionID)) continue } sectionMap[sectionID] = x.([]byte) @@ -670,17 +670,17 @@ func (iDB *InternalDB) GetConfigSectionsDrv(ctx *context.Context, tenant, nodeID return } -func (iDB *InternalDB) SetConfigSectionsDrv(ctx *context.Context, tenant, nodeID string, sectionsData map[string][]byte) (err error) { +func (iDB *InternalDB) SetConfigSectionsDrv(ctx *context.Context, nodeID string, sectionsData map[string][]byte) (err error) { for sectionID, sectionData := range sectionsData { - iDB.db.Set(utils.CacheConfig, utils.ConcatenatedKey(tenant, nodeID, sectionID), + iDB.db.Set(utils.CacheConfig, utils.ConcatenatedKey(nodeID, sectionID), sectionData, nil, true, utils.NonTransactional) } return } -func (iDB *InternalDB) RemoveConfigSectionsDrv(ctx *context.Context, tenant, nodeID string, sectionIDs []string) (err error) { +func (iDB *InternalDB) RemoveConfigSectionsDrv(ctx *context.Context, nodeID string, sectionIDs []string) (err error) { for _, sectionID := range sectionIDs { - iDB.db.Remove(utils.CacheConfig, utils.ConcatenatedKey(tenant, nodeID, sectionID), true, utils.NonTransactional) + iDB.db.Remove(utils.CacheConfig, utils.ConcatenatedKey(nodeID, sectionID), true, utils.NonTransactional) } return } diff --git a/engine/storage_it_test.go b/engine/storage_it_test.go index d1e2bad2f..36fe52058 100644 --- a/engine/storage_it_test.go +++ b/engine/storage_it_test.go @@ -44,7 +44,7 @@ func TestSetGetRemoveConfigSectionsDrvRedis(t *testing.T) { expected := make(map[string][]byte) // Try to retrieve the values before setting them (should receive an empty map) - if rcv, err := db.GetConfigSectionsDrv(context.Background(), "cgrates.org", "1234", sectionIDs); err == nil || + if rcv, err := db.GetConfigSectionsDrv(context.Background(), "1234", sectionIDs); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Errorf("expected: <%+v>, \nreceived: <%+v>", utils.ErrNotFound, err) } else if !reflect.DeepEqual(rcv, expected) { @@ -119,11 +119,11 @@ func TestSetGetRemoveConfigSectionsDrvRedis(t *testing.T) { "resources": rsJsnCfg, } - if err := db.SetConfigSectionsDrv(context.Background(), "cgrates.org", "1234", sectData); err != nil { + if err := db.SetConfigSectionsDrv(context.Background(), "1234", sectData); err != nil { t.Error(err) } - if rcv, err := db.GetConfigSectionsDrv(context.Background(), "cgrates.org", "1234", sectionIDs); err != nil { + if rcv, err := db.GetConfigSectionsDrv(context.Background(), "1234", sectionIDs); err != nil { t.Error(err) } else if !reflect.DeepEqual(rcv, sectData) { t.Errorf("expected: <%+v>, \nreceived: <%+v>", utils.ToJSON(sectData), utils.ToJSON(rcv)) @@ -140,11 +140,11 @@ func TestSetGetRemoveConfigSectionsDrvRedis(t *testing.T) { } } - if err := db.RemoveConfigSectionsDrv(context.Background(), "cgrates.org", "1234", sectionIDs); err != nil { + if err := db.RemoveConfigSectionsDrv(context.Background(), "1234", sectionIDs); err != nil { t.Error(err) } - if rcv, err := db.GetConfigSectionsDrv(context.Background(), "cgrates.org", "1234", sectionIDs); err == nil || + if rcv, err := db.GetConfigSectionsDrv(context.Background(), "1234", sectionIDs); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Errorf("expected: <%+v>, \nreceived: <%+v>", utils.ErrNotFound, err) } else if !reflect.DeepEqual(rcv, expected) { @@ -164,7 +164,7 @@ func TestSetGetRemoveConfigSectionsDrvMongo(t *testing.T) { expected := make(map[string][]byte) // Try to retrieve the values before setting them (should receive an empty map) - if rcv, err := db.GetConfigSectionsDrv(context.Background(), "cgrates.org", "1234", sectionIDs); err == nil || + if rcv, err := db.GetConfigSectionsDrv(context.Background(), "1234", sectionIDs); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Errorf("expected: <%+v>, \nreceived: <%+v>", utils.ErrNotFound, err) } else if !reflect.DeepEqual(rcv, expected) { @@ -239,11 +239,11 @@ func TestSetGetRemoveConfigSectionsDrvMongo(t *testing.T) { "resources": rsJsnCfg, } - if err := db.SetConfigSectionsDrv(context.Background(), "cgrates.org", "1234", sectData); err != nil { + if err := db.SetConfigSectionsDrv(context.Background(), "1234", sectData); err != nil { t.Error(err) } - if rcv, err := db.GetConfigSectionsDrv(context.Background(), "cgrates.org", "1234", sectionIDs); err != nil { + if rcv, err := db.GetConfigSectionsDrv(context.Background(), "1234", sectionIDs); err != nil { t.Error(err) } else if !reflect.DeepEqual(rcv, sectData) { t.Errorf("expected: <%+v>, \nreceived: <%+v>", utils.ToJSON(sectData), utils.ToJSON(rcv)) @@ -260,11 +260,11 @@ func TestSetGetRemoveConfigSectionsDrvMongo(t *testing.T) { } } - if err := db.RemoveConfigSectionsDrv(context.Background(), "cgrates.org", "1234", sectionIDs); err != nil { + if err := db.RemoveConfigSectionsDrv(context.Background(), "1234", sectionIDs); err != nil { t.Error(err) } - if rcv, err := db.GetConfigSectionsDrv(context.Background(), "cgrates.org", "1234", sectionIDs); err == nil || + if rcv, err := db.GetConfigSectionsDrv(context.Background(), "1234", sectionIDs); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Errorf("expected: <%+v>, \nreceived: <%+v>", utils.ErrNotFound, err) } else if !reflect.DeepEqual(rcv, expected) { @@ -282,7 +282,7 @@ func TestSetGetRemoveConfigSectionsDrvInternal(t *testing.T) { expected := make(map[string][]byte) // Try to retrieve the values before setting them (should receive an empty map) - if rcv, err := db.GetConfigSectionsDrv(context.Background(), "cgrates.org", "1234", sectionIDs); err == nil || + if rcv, err := db.GetConfigSectionsDrv(context.Background(), "1234", sectionIDs); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Errorf("expected: <%+v>, \nreceived: <%+v>", utils.ErrNotFound, err) } else if !reflect.DeepEqual(rcv, expected) { @@ -357,11 +357,11 @@ func TestSetGetRemoveConfigSectionsDrvInternal(t *testing.T) { "resources": rsJsnCfg, } - if err := db.SetConfigSectionsDrv(context.Background(), "cgrates.org", "1234", sectData); err != nil { + if err := db.SetConfigSectionsDrv(context.Background(), "1234", sectData); err != nil { t.Error(err) } - if rcv, err := db.GetConfigSectionsDrv(context.Background(), "cgrates.org", "1234", sectionIDs); err != nil { + if rcv, err := db.GetConfigSectionsDrv(context.Background(), "1234", sectionIDs); err != nil { t.Error(err) } else if !reflect.DeepEqual(rcv, sectData) { t.Errorf("expected: <%+v>, \nreceived: <%+v>", utils.ToJSON(sectData), utils.ToJSON(rcv)) @@ -378,11 +378,11 @@ func TestSetGetRemoveConfigSectionsDrvInternal(t *testing.T) { } } - if err := db.RemoveConfigSectionsDrv(context.Background(), "cgrates.org", "1234", sectionIDs); err != nil { + if err := db.RemoveConfigSectionsDrv(context.Background(), "1234", sectionIDs); err != nil { t.Error(err) } - if rcv, err := db.GetConfigSectionsDrv(context.Background(), "cgrates.org", "1234", sectionIDs); err == nil || + if rcv, err := db.GetConfigSectionsDrv(context.Background(), "1234", sectionIDs); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Errorf("expected: <%+v>, \nreceived: <%+v>", utils.ErrNotFound, err) } else if !reflect.DeepEqual(rcv, expected) { diff --git a/engine/storage_mongo_datadb.go b/engine/storage_mongo_datadb.go index df19a4bfb..bb432d5a4 100644 --- a/engine/storage_mongo_datadb.go +++ b/engine/storage_mongo_datadb.go @@ -1497,12 +1497,11 @@ func (ms *MongoStorage) RemoveAccountDrv(ctx *context.Context, tenant, id string }) } -func (ms *MongoStorage) GetConfigSectionsDrv(ctx *context.Context, tenant, nodeID string, sectionIDs []string) (sectionMap map[string][]byte, err error) { +func (ms *MongoStorage) GetConfigSectionsDrv(ctx *context.Context, nodeID string, sectionIDs []string) (sectionMap map[string][]byte, err error) { sectionMap = make(map[string][]byte) for _, sectionID := range sectionIDs { if err = ms.query(context.TODO(), func(sctx mongo.SessionContext) (err error) { cur := ms.getCol(ColCfg).FindOne(sctx, bson.M{ - "tenant": tenant, "nodeID": nodeID, "section": sectionID, }, options.FindOne().SetProjection(bson.M{"cfgData": 1, "_id": 0})) @@ -1527,15 +1526,13 @@ func (ms *MongoStorage) GetConfigSectionsDrv(ctx *context.Context, tenant, nodeI return } -func (ms *MongoStorage) SetConfigSectionsDrv(ctx *context.Context, tenant, nodeID string, sectionsData map[string][]byte) (err error) { +func (ms *MongoStorage) SetConfigSectionsDrv(ctx *context.Context, nodeID string, sectionsData map[string][]byte) (err error) { for sectionID, sectionData := range sectionsData { if err = ms.query(ctx, func(sctx mongo.SessionContext) (err error) { _, err = ms.getCol(ColCfg).UpdateOne(sctx, bson.M{ - "tenant": tenant, "nodeID": nodeID, "section": sectionID, }, bson.M{"$set": bson.M{ - "tenant": tenant, "nodeID": nodeID, "section": sectionID, "cfgData": sectionData}}, @@ -1549,11 +1546,10 @@ func (ms *MongoStorage) SetConfigSectionsDrv(ctx *context.Context, tenant, nodeI return } -func (ms *MongoStorage) RemoveConfigSectionsDrv(ctx *context.Context, tenant, nodeID string, sectionIDs []string) (err error) { +func (ms *MongoStorage) RemoveConfigSectionsDrv(ctx *context.Context, nodeID string, sectionIDs []string) (err error) { for _, sectionID := range sectionIDs { if err = ms.query(ctx, func(sctx mongo.SessionContext) (err error) { _, err = ms.getCol(ColCfg).DeleteOne(sctx, bson.M{ - "tenant": tenant, "nodeID": nodeID, "section": sectionID, }) diff --git a/engine/storage_redis.go b/engine/storage_redis.go index f1b1f37f4..8f9c96535 100644 --- a/engine/storage_redis.go +++ b/engine/storage_redis.go @@ -935,7 +935,7 @@ func (rs *RedisStorage) RemoveAccountDrv(ctx *context.Context, tenant, id string return rs.Cmd(nil, redisDEL, utils.AccountPrefix+utils.ConcatenatedKey(tenant, id)) } -func (rs *RedisStorage) GetConfigSectionsDrv(ctx *context.Context, tenant, nodeID string, sectionIDs []string) (sectionMap map[string][]byte, err error) { +func (rs *RedisStorage) GetConfigSectionsDrv(ctx *context.Context, nodeID string, sectionIDs []string) (sectionMap map[string][]byte, err error) { sectionMap = make(map[string][]byte) if len(sectionIDs) == 0 { if err = rs.Cmd(§ionMap, redisHGETALL, utils.ConfigPrefix+nodeID); err != nil { @@ -959,14 +959,14 @@ func (rs *RedisStorage) GetConfigSectionsDrv(ctx *context.Context, tenant, nodeI return } -func (rs *RedisStorage) SetConfigSectionsDrv(ctx *context.Context, tenant, nodeID string, sectionsData map[string][]byte) (err error) { +func (rs *RedisStorage) SetConfigSectionsDrv(ctx *context.Context, nodeID string, sectionsData map[string][]byte) (err error) { if err = rs.FlatCmd(nil, redisHSET, utils.ConfigPrefix+nodeID, sectionsData); err != nil { return } return } -func (rs *RedisStorage) RemoveConfigSectionsDrv(ctx *context.Context, tenant, nodeID string, sectionIDs []string) (err error) { +func (rs *RedisStorage) RemoveConfigSectionsDrv(ctx *context.Context, nodeID string, sectionIDs []string) (err error) { if err = rs.FlatCmd(nil, redisHDEL, utils.ConfigPrefix+nodeID, sectionIDs); err != nil { return }