added RemoveActionTrigger api

fixes #431
This commit is contained in:
Radu Ioan Fericean
2016-06-28 12:24:46 +03:00
parent ed4e6dc81f
commit 48edfbb6de
5 changed files with 60 additions and 0 deletions

View File

@@ -318,6 +318,47 @@ func (self *ApierV1) SetAccountActionTriggers(attr AttrSetAccountActionTriggers,
return nil
}
type AttrRemoveActionTrigger struct {
GroupID string
UniqueID string
}
func (self *ApierV1) RemoveActionTrigger(attr AttrRemoveActionTrigger, reply *string) error {
if missing := utils.MissingStructFields(&attr, []string{"GroupID"}); len(missing) != 0 {
return utils.NewErrMandatoryIeMissing(missing...)
}
if attr.UniqueID == "" {
err := self.RatingDb.RemoveActionTriggers(attr.GroupID)
if err != nil {
*reply = err.Error()
} else {
*reply = utils.OK
}
return err
} else {
atrs, err := self.RatingDb.GetActionTriggers(attr.GroupID)
if err != nil {
*reply = err.Error()
return err
}
var remainingAtrs engine.ActionTriggers
for _, atr := range atrs {
if atr.UniqueID == attr.UniqueID {
continue
}
remainingAtrs = append(remainingAtrs, atr)
}
// set the cleared list back
err = self.RatingDb.SetActionTriggers(attr.GroupID, remainingAtrs)
if err != nil {
*reply = err.Error()
} else {
*reply = utils.OK
}
return err
}
}
type AttrSetActionTrigger struct {
GroupID string
UniqueID string

View File

@@ -65,6 +65,7 @@ type RatingStorage interface {
SetSharedGroup(*SharedGroup) error
GetActionTriggers(string) (ActionTriggers, error)
SetActionTriggers(string, ActionTriggers) error
RemoveActionTriggers(string) error
GetActionPlan(string, bool) (*ActionPlan, error)
SetActionPlan(string, *ActionPlan, bool) error
GetAllActionPlans() (map[string]*ActionPlan, error)

View File

@@ -732,6 +732,13 @@ func (ms *MapStorage) SetActionTriggers(key string, atrs ActionTriggers) (err er
return
}
func (ms *MapStorage) RemoveActionTriggers(key string) (err error) {
ms.mu.Lock()
defer ms.mu.Unlock()
delete(ms.dict, utils.ACTION_TRIGGER_PREFIX+key)
return
}
func (ms *MapStorage) GetActionPlan(key string, skipCache bool) (ats *ActionPlan, err error) {
ms.mu.RLock()
defer ms.mu.RUnlock()

View File

@@ -1320,6 +1320,12 @@ func (ms *MongoStorage) SetActionTriggers(key string, atrs ActionTriggers) (err
return err
}
func (ms *MongoStorage) RemoveActionTriggers(key string) error {
session, col := ms.conn(colAtr)
defer session.Close()
return col.Remove(bson.M{"key": key})
}
func (ms *MongoStorage) GetActionPlan(key string, skipCache bool) (ats *ActionPlan, err error) {
if !skipCache {
if x, err := cache2go.Get(utils.ACTION_PLAN_PREFIX + key); err == nil {

View File

@@ -956,6 +956,11 @@ func (rs *RedisStorage) SetActionTriggers(key string, atrs ActionTriggers) (err
return conn.Cmd("SET", utils.ACTION_TRIGGER_PREFIX+key, result).Err
}
func (rs *RedisStorage) RemoveActionTriggers(key string) (err error) {
err = rs.db.Cmd("DEL", utils.ACTION_TRIGGER_PREFIX+key).Err
return
}
func (rs *RedisStorage) GetActionPlan(key string, skipCache bool) (ats *ActionPlan, err error) {
key = utils.ACTION_PLAN_PREFIX + key
if !skipCache {