Remove tenant from arguments for config storage functions

This commit is contained in:
ionutboangiu
2022-03-02 15:04:28 +02:00
committed by Dan Christian Bogos
parent a6e2ca3b77
commit 5d2089979c
6 changed files with 35 additions and 39 deletions

View File

@@ -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
}

View File

@@ -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

View File

@@ -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
}

View File

@@ -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) {

View File

@@ -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,
})

View File

@@ -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(&sectionMap, 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
}