mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-21 07:08:45 +05:00
started RemActions API
This commit is contained in:
@@ -1064,3 +1064,48 @@ func (self *ApierV1) GetLoadHistory(attrs utils.Paginator, reply *[]*engine.Load
|
||||
*reply = loadHist[offset:nrItems]
|
||||
return nil
|
||||
}
|
||||
|
||||
type AttrRemActions struct {
|
||||
ActionIDs []string
|
||||
}
|
||||
|
||||
func (self *ApierV1) RemActions(attr AttrRemActions, reply *string) error {
|
||||
if attr.ActionIDs == nil {
|
||||
return nil
|
||||
}
|
||||
stringMap := utils.NewStringMap(attr.ActionIDs...)
|
||||
keys, err := self.RatingDb.GetKeysForPrefix(utils.ACTION_TRIGGER_PREFIX, true)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
for _, key := range keys {
|
||||
getAttrs, err := self.RatingDb.GetActionTriggers(key[len(utils.ACTION_TRIGGER_PREFIX):])
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
for _, atr := range getAttrs {
|
||||
if _, found := stringMap[atr.ActionsID]; found {
|
||||
// found action trigger referencing action; abort
|
||||
return fmt.Errorf("action %s refenced by action trigger %s", atr.ActionsID, atr.ID)
|
||||
}
|
||||
}
|
||||
}
|
||||
allAplsMap, err := self.RatingDb.GetAllActionPlans()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
for _, apl := range allAplsMap {
|
||||
for _, aID := range attr.ActionIDs {
|
||||
if _, found := apl.AccountIDs[aID]; found {
|
||||
return fmt.Errorf("action %s refenced by action plan %s", aID, apl.Id)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
for _, aID := range attr.ActionIDs {
|
||||
if err := self.RatingDb.RemoveActions(aID); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -59,6 +59,7 @@ type RatingStorage interface {
|
||||
SetDerivedChargers(string, *utils.DerivedChargers) error
|
||||
GetActions(string, bool) (Actions, error)
|
||||
SetActions(string, Actions) error
|
||||
RemoveActions(string) error
|
||||
GetSharedGroup(string, bool) (*SharedGroup, error)
|
||||
SetSharedGroup(*SharedGroup) error
|
||||
GetActionTriggers(string) (ActionTriggers, error)
|
||||
|
||||
@@ -469,6 +469,13 @@ func (ms *MapStorage) SetActions(key string, as Actions) (err error) {
|
||||
return
|
||||
}
|
||||
|
||||
func (ms *MapStorage) RemoveActions(key string) (err error) {
|
||||
ms.mu.Lock()
|
||||
defer ms.mu.Unlock()
|
||||
delete(ms.dict, utils.ACTION_PREFIX+key)
|
||||
return
|
||||
}
|
||||
|
||||
func (ms *MapStorage) GetSharedGroup(key string, skipCache bool) (sg *SharedGroup, err error) {
|
||||
ms.mu.RLock()
|
||||
defer ms.mu.RUnlock()
|
||||
|
||||
@@ -916,6 +916,10 @@ func (ms *MongoStorage) SetActions(key string, as Actions) error {
|
||||
return err
|
||||
}
|
||||
|
||||
func (ms *MongoStorage) RemoveActions(key string) error {
|
||||
return ms.db.C(colAct).Remove(bson.M{"key": key})
|
||||
}
|
||||
|
||||
func (ms *MongoStorage) GetSharedGroup(key string, skipCache bool) (sg *SharedGroup, err error) {
|
||||
if !skipCache {
|
||||
if x, err := cache2go.Get(utils.SHARED_GROUP_PREFIX + key); err == nil {
|
||||
|
||||
@@ -590,6 +590,11 @@ func (rs *RedisStorage) SetActions(key string, as Actions) (err error) {
|
||||
return
|
||||
}
|
||||
|
||||
func (rs *RedisStorage) RemoveActions(key string) (err error) {
|
||||
err = rs.db.Cmd("DEL", utils.ACTION_PREFIX+key).Err
|
||||
return
|
||||
}
|
||||
|
||||
func (rs *RedisStorage) GetSharedGroup(key string, skipCache bool) (sg *SharedGroup, err error) {
|
||||
key = utils.SHARED_GROUP_PREFIX + key
|
||||
if !skipCache {
|
||||
|
||||
Reference in New Issue
Block a user