diff --git a/engine/account.go b/engine/account.go index 2ca818ed1..1c0ede2bd 100644 --- a/engine/account.go +++ b/engine/account.go @@ -168,7 +168,7 @@ func (acc *Account) setBalanceAction(a *Action) error { sg.MemberIds = make(utils.StringMap) } sg.MemberIds[acc.ID] = true - dm.DataDB().SetSharedGroup(sg, utils.NonTransactional) + dm.SetSharedGroup(sg, utils.NonTransactional) } } i++ @@ -260,7 +260,7 @@ func (ub *Account) debitBalanceAction(a *Action, reset bool) error { sg.MemberIds = make(utils.StringMap) } sg.MemberIds[ub.ID] = true - dm.DataDB().SetSharedGroup(sg, utils.NonTransactional) + dm.SetSharedGroup(sg, utils.NonTransactional) } } i++ diff --git a/engine/account_test.go b/engine/account_test.go index baa5f4fcd..eda9563e2 100644 --- a/engine/account_test.go +++ b/engine/account_test.go @@ -1248,7 +1248,7 @@ func TestDebitShared(t *testing.T) { sg := &SharedGroup{Id: "SG_TEST", MemberIds: utils.NewStringMap(rif.ID, groupie.ID), AccountParameters: map[string]*SharingParameters{"*any": &SharingParameters{Strategy: STRATEGY_MINE_RANDOM}}} dm.DataDB().SetAccount(groupie) - dm.DataDB().SetSharedGroup(sg, utils.NonTransactional) + dm.SetSharedGroup(sg, utils.NonTransactional) cc, err := rif.debitCreditBalance(cd, false, false, true) if err != nil { t.Error("Error debiting balance: ", err) @@ -1317,7 +1317,7 @@ func TestMaxDurationShared(t *testing.T) { sg := &SharedGroup{Id: "SG_TEST", MemberIds: utils.NewStringMap(rif.ID, groupie.ID), AccountParameters: map[string]*SharingParameters{"*any": &SharingParameters{Strategy: STRATEGY_MINE_RANDOM}}} dm.DataDB().SetAccount(groupie) - dm.DataDB().SetSharedGroup(sg, utils.NonTransactional) + dm.SetSharedGroup(sg, utils.NonTransactional) duration, err := cd.getMaxSessionDuration(rif) if err != nil { t.Error("Error getting max session duration from shared group: ", err) diff --git a/engine/datamanager.go b/engine/datamanager.go index 5fabf4696..2b48ff16b 100644 --- a/engine/datamanager.go +++ b/engine/datamanager.go @@ -577,3 +577,14 @@ func (dm *DataManager) GetSharedGroup(key string, skipCache bool, transactionID return } + +func (dm *DataManager) SetSharedGroup(sg *SharedGroup, transactionID string) (err error) { + if dm.DataDB().GetStorageType() == utils.MAPSTOR { + if err = dm.DataDB().SetSharedGroupDrv(sg); err != nil { + cache.RemKey(utils.SHARED_GROUP_PREFIX+sg.Id, cacheCommit(transactionID), transactionID) + } + return + } else { + return dm.DataDB().SetSharedGroupDrv(sg) + } +} diff --git a/engine/onstor_it_test.go b/engine/onstor_it_test.go index a08024c15..6c42f9cb0 100644 --- a/engine/onstor_it_test.go +++ b/engine/onstor_it_test.go @@ -589,7 +589,7 @@ func testOnStorITCacheSharedGroup(t *testing.T) { }, MemberIds: make(utils.StringMap), } - if err := onStor.DataDB().SetSharedGroup(sg, utils.NonTransactional); err != nil { + if err := onStor.SetSharedGroup(sg, utils.NonTransactional); err != nil { t.Error(err) } expectedCSh := []string{"shg_SG1"} @@ -1358,7 +1358,7 @@ func testOnStorITCRUDSharedGroup(t *testing.T) { if _, rcvErr := onStor.GetSharedGroup(sg.Id, true, utils.NonTransactional); rcvErr != utils.ErrNotFound { t.Error(rcvErr) } - if err := onStor.DataDB().SetSharedGroup(sg, utils.NonTransactional); err != nil { + if err := onStor.SetSharedGroup(sg, utils.NonTransactional); err != nil { t.Error(err) } if rcv, err := onStor.GetSharedGroup(sg.Id, true, utils.NonTransactional); err != nil { diff --git a/engine/sharedgroup_test.go b/engine/sharedgroup_test.go index 9249ecfc8..f20d5a64d 100644 --- a/engine/sharedgroup_test.go +++ b/engine/sharedgroup_test.go @@ -33,7 +33,7 @@ func TestSharedSetGet(t *testing.T) { }, MemberIds: utils.NewStringMap("1", "2", "3"), } - err := dm.DataDB().SetSharedGroup(sg, utils.NonTransactional) + err := dm.SetSharedGroup(sg, utils.NonTransactional) if err != nil { t.Error("Error storing Shared groudp: ", err) } diff --git a/engine/storage_interface.go b/engine/storage_interface.go index a5ea5889d..a26639e57 100755 --- a/engine/storage_interface.go +++ b/engine/storage_interface.go @@ -70,7 +70,7 @@ type DataDB interface { SetActions(string, Actions, string) error RemoveActions(string, string) error GetSharedGroupDrv(string) (*SharedGroup, error) - SetSharedGroup(*SharedGroup, string) error + SetSharedGroupDrv(*SharedGroup) error GetActionTriggersDrv(string) (ActionTriggers, error) SetActionTriggersDrv(string, ActionTriggers) error RemoveActionTriggersDrv(string) error diff --git a/engine/storage_map.go b/engine/storage_map.go index da3cbb12c..54b9f458c 100755 --- a/engine/storage_map.go +++ b/engine/storage_map.go @@ -531,12 +531,11 @@ func (ms *MapStorage) GetSharedGroupDrv(key string) (sg *SharedGroup, err error) return } -func (ms *MapStorage) SetSharedGroup(sg *SharedGroup, transactionID string) (err error) { +func (ms *MapStorage) SetSharedGroupDrv(sg *SharedGroup) (err error) { ms.mu.Lock() defer ms.mu.Unlock() result, err := ms.ms.Marshal(sg) ms.dict[utils.SHARED_GROUP_PREFIX+sg.Id] = result - cache.RemKey(utils.SHARED_GROUP_PREFIX+sg.Id, cacheCommit(transactionID), transactionID) return } diff --git a/engine/storage_mongo_datadb.go b/engine/storage_mongo_datadb.go index 7b869d230..67c1908f9 100755 --- a/engine/storage_mongo_datadb.go +++ b/engine/storage_mongo_datadb.go @@ -1018,7 +1018,7 @@ func (ms *MongoStorage) GetSharedGroupDrv(key string) (sg *SharedGroup, err erro return } -func (ms *MongoStorage) SetSharedGroup(sg *SharedGroup, transactionID string) (err error) { +func (ms *MongoStorage) SetSharedGroupDrv(sg *SharedGroup) (err error) { session, col := ms.conn(colShg) defer session.Close() if _, err = col.Upsert(bson.M{"id": sg.Id}, sg); err != nil { diff --git a/engine/storage_redis.go b/engine/storage_redis.go index e9ce51dd1..9906d7966 100755 --- a/engine/storage_redis.go +++ b/engine/storage_redis.go @@ -574,7 +574,7 @@ func (rs *RedisStorage) GetSharedGroupDrv(key string) (sg *SharedGroup, err erro return } -func (rs *RedisStorage) SetSharedGroup(sg *SharedGroup, transactionID string) (err error) { +func (rs *RedisStorage) SetSharedGroupDrv(sg *SharedGroup) (err error) { var result []byte if result, err = rs.ms.Marshal(sg); err != nil { return diff --git a/engine/tp_reader.go b/engine/tp_reader.go index e55efa2c1..119cdb35b 100755 --- a/engine/tp_reader.go +++ b/engine/tp_reader.go @@ -465,7 +465,7 @@ func (tpr *TpReader) LoadSharedGroupsFiltered(tag string, save bool) (err error) } if save { for _, sg := range tpr.sharedGroups { - if err := tpr.dm.DataDB().SetSharedGroup(sg, utils.NonTransactional); err != nil { + if err := tpr.dm.SetSharedGroup(sg, utils.NonTransactional); err != nil { return err } } @@ -1914,7 +1914,7 @@ func (tpr *TpReader) WriteToDatabase(flush, verbose, disable_reverse bool) (err log.Print("Shared Groups:") } for k, sg := range tpr.sharedGroups { - err = tpr.dm.DataDB().SetSharedGroup(sg, utils.NonTransactional) + err = tpr.dm.SetSharedGroup(sg, utils.NonTransactional) if err != nil { return err } diff --git a/migrator/sharedgroup.go b/migrator/sharedgroup.go index 698940ece..8976052d8 100644 --- a/migrator/sharedgroup.go +++ b/migrator/sharedgroup.go @@ -44,7 +44,7 @@ func (m *Migrator) migrateSharedGroups() (err error) { if v1SG != nil { acnt := v1SG.AsSharedGroup() if m.dryRun != true { - if err = m.dm.DataDB().SetSharedGroup(acnt, utils.NonTransactional); err != nil { + if err = m.dm.SetSharedGroup(acnt, utils.NonTransactional); err != nil { return err } m.stats[utils.SharedGroups] += 1