From 35ad39685efb3cf7f26eb110fbb5a549c5d2071e Mon Sep 17 00:00:00 2001 From: TeoV Date: Fri, 20 Oct 2017 18:54:44 +0300 Subject: [PATCH] Add RemoveActions in DataManager --- apier/v1/apier.go | 2 +- engine/datamanager.go | 8 ++++++++ engine/onstor_it_test.go | 2 +- engine/storage_interface.go | 2 +- engine/storage_map.go | 3 +-- engine/storage_mongo_datadb.go | 3 +-- engine/storage_redis.go | 3 +-- 7 files changed, 14 insertions(+), 9 deletions(-) diff --git a/apier/v1/apier.go b/apier/v1/apier.go index 7def5dbff..85af05696 100644 --- a/apier/v1/apier.go +++ b/apier/v1/apier.go @@ -1709,7 +1709,7 @@ func (self *ApierV1) RemoveActions(attr AttrRemoveActions, reply *string) error } */ for _, aID := range attr.ActionIDs { - if err := self.DataManager.DataDB().RemoveActions(aID, utils.NonTransactional); err != nil { + if err := self.DataManager.RemoveActions(aID, utils.NonTransactional); err != nil { *reply = err.Error() return err } diff --git a/engine/datamanager.go b/engine/datamanager.go index 0f0946dac..a982c6f84 100644 --- a/engine/datamanager.go +++ b/engine/datamanager.go @@ -656,3 +656,11 @@ func (dm *DataManager) SetActions(key string, as Actions, transactionID string) return dm.DataDB().SetActionsDrv(key, as) } } + +func (dm *DataManager) RemoveActions(key, transactionID string) (err error) { + if err = dm.DataDB().RemoveActionsDrv(key); err != nil { + return + } + cache.RemKey(utils.ACTION_PREFIX+key, cacheCommit(transactionID), transactionID) + return +} diff --git a/engine/onstor_it_test.go b/engine/onstor_it_test.go index 554f11995..9e447510f 100644 --- a/engine/onstor_it_test.go +++ b/engine/onstor_it_test.go @@ -1335,7 +1335,7 @@ func testOnStorITCRUDActions(t *testing.T) { // t.Error(err) // } - if err := onStor.DataDB().RemoveActions(acts[0].Id, utils.NonTransactional); err != nil { + if err := onStor.RemoveActions(acts[0].Id, utils.NonTransactional); err != nil { t.Error(err) } if _, rcvErr := onStor.GetActions(acts[0].Id, true, utils.NonTransactional); rcvErr != utils.ErrNotFound { diff --git a/engine/storage_interface.go b/engine/storage_interface.go index f1f84747f..946dad410 100755 --- a/engine/storage_interface.go +++ b/engine/storage_interface.go @@ -68,7 +68,7 @@ type DataDB interface { SetDerivedChargers(string, *utils.DerivedChargers, string) error GetActionsDrv(string) (Actions, error) SetActionsDrv(string, Actions) error - RemoveActions(string, string) error + RemoveActionsDrv(string) error GetSharedGroupDrv(string) (*SharedGroup, error) SetSharedGroupDrv(*SharedGroup) error GetActionTriggersDrv(string) (ActionTriggers, error) diff --git a/engine/storage_map.go b/engine/storage_map.go index bea5b8b0e..1d24b1240 100755 --- a/engine/storage_map.go +++ b/engine/storage_map.go @@ -492,12 +492,11 @@ func (ms *MapStorage) SetActionsDrv(key string, as Actions) (err error) { return } -func (ms *MapStorage) RemoveActions(key string, transactionID string) (err error) { +func (ms *MapStorage) RemoveActionsDrv(key string) (err error) { cachekey := utils.ACTION_PREFIX + key ms.mu.Lock() delete(ms.dict, cachekey) ms.mu.Unlock() - cache.RemKey(cachekey, cacheCommit(transactionID), transactionID) return } diff --git a/engine/storage_mongo_datadb.go b/engine/storage_mongo_datadb.go index e07726dd3..f23015460 100755 --- a/engine/storage_mongo_datadb.go +++ b/engine/storage_mongo_datadb.go @@ -984,11 +984,10 @@ func (ms *MongoStorage) SetActionsDrv(key string, as Actions) error { return err } -func (ms *MongoStorage) RemoveActions(key string, transactionID string) error { +func (ms *MongoStorage) RemoveActionsDrv(key string) error { session, col := ms.conn(colAct) defer session.Close() err := col.Remove(bson.M{"key": key}) - cache.RemKey(utils.ACTION_PREFIX+key, cacheCommit(transactionID), transactionID) return err } diff --git a/engine/storage_redis.go b/engine/storage_redis.go index 6d804493d..1f9dd3dd7 100755 --- a/engine/storage_redis.go +++ b/engine/storage_redis.go @@ -540,9 +540,8 @@ func (rs *RedisStorage) SetActionsDrv(key string, as Actions) (err error) { return } -func (rs *RedisStorage) RemoveActions(key string, transactionID string) (err error) { +func (rs *RedisStorage) RemoveActionsDrv(key string) (err error) { err = rs.Cmd("DEL", utils.ACTION_PREFIX+key).Err - cache.RemKey(utils.ACTION_PREFIX+key, cacheCommit(transactionID), transactionID) return }