mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-16 21:59:53 +05:00
Add SetActions in DataManager
This commit is contained in:
committed by
Dan Christian Bogos
parent
9f68b27b27
commit
1546720116
@@ -554,7 +554,7 @@ func (self *ApierV1) SetActions(attrs V1AttrSetActions, reply *string) (err erro
|
||||
}
|
||||
storeActions[idx] = a
|
||||
}
|
||||
if err := self.DataManager.DataDB().SetActions(attrs.ActionsId, storeActions, utils.NonTransactional); err != nil {
|
||||
if err := self.DataManager.SetActions(attrs.ActionsId, storeActions, utils.NonTransactional); err != nil {
|
||||
return utils.NewErrServerError(err)
|
||||
}
|
||||
if err = self.DataManager.CacheDataFromDB(utils.ACTION_PREFIX, []string{attrs.ActionsId}, true); err != nil {
|
||||
|
||||
@@ -373,7 +373,7 @@ func (self *ApierV2) SetActions(attrs utils.AttrSetActions, reply *string) error
|
||||
}
|
||||
storeActions[idx] = a
|
||||
}
|
||||
if err := self.DataManager.DataDB().SetActions(attrs.ActionsId, storeActions, utils.NonTransactional); err != nil {
|
||||
if err := self.DataManager.SetActions(attrs.ActionsId, storeActions, utils.NonTransactional); err != nil {
|
||||
return utils.NewErrServerError(err)
|
||||
}
|
||||
if err := self.DataManager.CacheDataFromDB(utils.ACTION_PREFIX, []string{attrs.ActionsId}, true); err != nil {
|
||||
|
||||
@@ -580,7 +580,7 @@ func TestActionPlansRemoveMember(t *testing.T) {
|
||||
},
|
||||
}
|
||||
|
||||
dm.DataDB().SetActions(actions[0].Id, actions, utils.NonTransactional)
|
||||
dm.SetActions(actions[0].Id, actions, utils.NonTransactional)
|
||||
|
||||
at := &ActionTiming{
|
||||
accountIDs: utils.StringMap{account1.ID: true},
|
||||
|
||||
@@ -100,8 +100,8 @@ func populateDB() {
|
||||
}},
|
||||
}
|
||||
if dm.dataDB != nil {
|
||||
dm.DataDB().SetActions("TEST_ACTIONS", ats, utils.NonTransactional)
|
||||
dm.DataDB().SetActions("TEST_ACTIONS_ORDER", ats1, utils.NonTransactional)
|
||||
dm.SetActions("TEST_ACTIONS", ats, utils.NonTransactional)
|
||||
dm.SetActions("TEST_ACTIONS_ORDER", ats1, utils.NonTransactional)
|
||||
dm.DataDB().SetAccount(broker)
|
||||
dm.DataDB().SetAccount(minu)
|
||||
dm.DataDB().SetAccount(minitsboy)
|
||||
|
||||
@@ -645,3 +645,14 @@ func (dm *DataManager) GetActions(key string, skipCache bool, transactionID stri
|
||||
return
|
||||
|
||||
}
|
||||
|
||||
func (dm *DataManager) SetActions(key string, as Actions, transactionID string) (err error) {
|
||||
if dm.DataDB().GetStorageType() == utils.MAPSTOR {
|
||||
if err = dm.DataDB().SetActionsDrv(key, as); err != nil {
|
||||
cache.RemKey(utils.ACTION_PREFIX+key, cacheCommit(transactionID), transactionID)
|
||||
}
|
||||
return
|
||||
} else {
|
||||
return dm.DataDB().SetActionsDrv(key, as)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -445,7 +445,7 @@ func testOnStorITCacheActions(t *testing.T) {
|
||||
},
|
||||
},
|
||||
}
|
||||
if err := onStor.DataDB().SetActions(acts[0].Id, acts, utils.NonTransactional); err != nil {
|
||||
if err := onStor.SetActions(acts[0].Id, acts, utils.NonTransactional); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
expectedCA := []string{"act_MINI"}
|
||||
@@ -1310,7 +1310,7 @@ func testOnStorITCRUDActions(t *testing.T) {
|
||||
if _, rcvErr := onStor.GetActions(acts[0].Id, true, utils.NonTransactional); rcvErr != utils.ErrNotFound {
|
||||
t.Error(rcvErr)
|
||||
}
|
||||
if err := onStor.DataDB().SetActions(acts[0].Id, acts, utils.NonTransactional); err != nil {
|
||||
if err := onStor.SetActions(acts[0].Id, acts, utils.NonTransactional); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
if rcv, err := onStor.GetActions(acts[0].Id, true, utils.NonTransactional); err != nil {
|
||||
|
||||
@@ -67,7 +67,7 @@ type DataDB interface {
|
||||
GetDerivedChargersDrv(string) (*utils.DerivedChargers, error)
|
||||
SetDerivedChargers(string, *utils.DerivedChargers, string) error
|
||||
GetActionsDrv(string) (Actions, error)
|
||||
SetActions(string, Actions, string) error
|
||||
SetActionsDrv(string, Actions) error
|
||||
RemoveActions(string, string) error
|
||||
GetSharedGroupDrv(string) (*SharedGroup, error)
|
||||
SetSharedGroupDrv(*SharedGroup) error
|
||||
|
||||
@@ -483,14 +483,12 @@ func (ms *MapStorage) GetActionsDrv(key string) (as Actions, err error) {
|
||||
return
|
||||
}
|
||||
|
||||
func (ms *MapStorage) SetActions(key string, as Actions, transactionID string) (err error) {
|
||||
func (ms *MapStorage) SetActionsDrv(key string, as Actions) (err error) {
|
||||
ms.mu.Lock()
|
||||
defer ms.mu.Unlock()
|
||||
cCommit := cacheCommit(transactionID)
|
||||
cachekey := utils.ACTION_PREFIX + key
|
||||
result, err := ms.ms.Marshal(&as)
|
||||
ms.dict[cachekey] = result
|
||||
cache.RemKey(cachekey, cCommit, transactionID)
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
@@ -974,7 +974,7 @@ func (ms *MongoStorage) GetActionsDrv(key string) (as Actions, err error) {
|
||||
return
|
||||
}
|
||||
|
||||
func (ms *MongoStorage) SetActions(key string, as Actions, transactionID string) error {
|
||||
func (ms *MongoStorage) SetActionsDrv(key string, as Actions) error {
|
||||
session, col := ms.conn(colAct)
|
||||
defer session.Close()
|
||||
_, err := col.Upsert(bson.M{"key": key}, &struct {
|
||||
|
||||
@@ -534,7 +534,7 @@ func (rs *RedisStorage) GetActionsDrv(key string) (as Actions, err error) {
|
||||
return
|
||||
}
|
||||
|
||||
func (rs *RedisStorage) SetActions(key string, as Actions, transactionID string) (err error) {
|
||||
func (rs *RedisStorage) SetActionsDrv(key string, as Actions) (err error) {
|
||||
result, err := rs.ms.Marshal(&as)
|
||||
err = rs.Cmd("SET", utils.ACTION_PREFIX+key, result).Err
|
||||
return
|
||||
|
||||
@@ -1124,7 +1124,7 @@ func (tpr *TpReader) LoadAccountActionsFiltered(qriedAA *utils.TPAccountActions)
|
||||
}
|
||||
// write actions
|
||||
for k, as := range facts {
|
||||
err = tpr.dm.DataDB().SetActions(k, as, utils.NonTransactional)
|
||||
err = tpr.dm.SetActions(k, as, utils.NonTransactional)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -1453,7 +1453,7 @@ func (tpr *TpReader) LoadCdrStatsFiltered(tag string, save bool) (err error) {
|
||||
if save {
|
||||
// write actions
|
||||
for k, as := range tpr.actions {
|
||||
err = tpr.dm.DataDB().SetActions(k, as, utils.NonTransactional)
|
||||
err = tpr.dm.SetActions(k, as, utils.NonTransactional)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -1938,7 +1938,7 @@ func (tpr *TpReader) WriteToDatabase(flush, verbose, disable_reverse bool) (err
|
||||
log.Print("Actions:")
|
||||
}
|
||||
for k, as := range tpr.actions {
|
||||
err = tpr.dm.DataDB().SetActions(k, as, utils.NonTransactional)
|
||||
err = tpr.dm.SetActions(k, as, utils.NonTransactional)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -56,7 +56,7 @@ func (m *Migrator) migrateActions() (err error) {
|
||||
|
||||
}
|
||||
if m.dryRun != true {
|
||||
if err := m.dm.DataDB().SetActions(acts[0].Id, acts, utils.NonTransactional); err != nil {
|
||||
if err := m.dm.SetActions(acts[0].Id, acts, utils.NonTransactional); err != nil {
|
||||
return err
|
||||
}
|
||||
m.stats[utils.Actions] += 1
|
||||
|
||||
Reference in New Issue
Block a user