mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-11 18:16:24 +05:00
started destination removal feature
This commit is contained in:
@@ -63,6 +63,15 @@ func (self *ApierV1) GetDestination(dstId string, reply *engine.Destination) err
|
||||
return nil
|
||||
}
|
||||
|
||||
type AttrRemoveDestination struct {
|
||||
DestinationIDs []string
|
||||
Prefixes []string
|
||||
}
|
||||
|
||||
func (self *ApierV1) RemoveDestination(attr AttrRemoveDestination, reply *string) error {
|
||||
|
||||
}
|
||||
|
||||
func (apier *ApierV1) GetSharedGroup(sgId string, reply *engine.SharedGroup) error {
|
||||
if sg, err := apier.RatingDb.GetSharedGroup(sgId, false); err != nil && err != utils.ErrNotFound { // Not found is not an error here
|
||||
return err
|
||||
|
||||
@@ -63,12 +63,13 @@ func (d *Destination) AddPrefix(pfx string) {
|
||||
}
|
||||
|
||||
// history record method
|
||||
func (d *Destination) GetHistoryRecord() history.Record {
|
||||
func (d *Destination) GetHistoryRecord(deleted bool) history.Record {
|
||||
js, _ := json.Marshal(d)
|
||||
return history.Record{
|
||||
Id: d.Id,
|
||||
Filename: history.DESTINATIONS_FN,
|
||||
Payload: js,
|
||||
Deleted: deleted,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -50,6 +50,7 @@ type RatingStorage interface {
|
||||
RemoveRatingProfile(string) error
|
||||
GetDestination(string) (*Destination, error)
|
||||
SetDestination(*Destination) error
|
||||
RemoveDestination(string) error
|
||||
GetLCR(string, bool) (*LCR, error)
|
||||
SetLCR(*LCR) error
|
||||
SetCdrStats(*CdrStats) error
|
||||
|
||||
@@ -436,7 +436,7 @@ func (ms *MapStorage) SetDestination(dest *Destination) (err error) {
|
||||
ms.dict[utils.DESTINATION_PREFIX+dest.Id] = b.Bytes()
|
||||
response := 0
|
||||
if historyScribe != nil {
|
||||
go historyScribe.Call("HistoryV1.Record", dest.GetHistoryRecord(), &response)
|
||||
go historyScribe.Call("HistoryV1.Record", dest.GetHistoryRecord(false), &response)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
@@ -883,7 +883,7 @@ func (ms *MongoStorage) SetDestination(dest *Destination) (err error) {
|
||||
}{Key: dest.Id, Value: b.Bytes()})
|
||||
if err == nil && historyScribe != nil {
|
||||
var response int
|
||||
historyScribe.Call("HistoryV1.Record", dest.GetHistoryRecord(), &response)
|
||||
historyScribe.Call("HistoryV1.Record", dest.GetHistoryRecord(false), &response)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
@@ -545,7 +545,7 @@ func (rs *RedisStorage) GetDestination(key string) (dest *Destination, err error
|
||||
cache2go.Push(utils.DESTINATION_PREFIX+p, dest.Id)
|
||||
}
|
||||
} else {
|
||||
return nil, errors.New("not found")
|
||||
return nil, utils.ErrNotFound
|
||||
}
|
||||
return
|
||||
}
|
||||
@@ -562,11 +562,66 @@ func (rs *RedisStorage) SetDestination(dest *Destination) (err error) {
|
||||
err = rs.db.Cmd("SET", utils.DESTINATION_PREFIX+dest.Id, b.Bytes()).Err
|
||||
if err == nil && historyScribe != nil {
|
||||
response := 0
|
||||
go historyScribe.Call("HistoryV1.Record", dest.GetHistoryRecord(), &response)
|
||||
go historyScribe.Call("HistoryV1.Record", dest.GetHistoryRecord(false), &response)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (rs *RedisStorage) RemoveDestination(destID string) (err error) {
|
||||
conn, err := rs.db.Get()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
var dest *Destination
|
||||
defer rs.db.Put(conn)
|
||||
if values, err = conn.Cmd("GET", key).Bytes(); len(values) > 0 && err == nil {
|
||||
b := bytes.NewBuffer(values)
|
||||
r, err := zlib.NewReader(b)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
out, err := ioutil.ReadAll(r)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
r.Close()
|
||||
dest = new(Destination)
|
||||
err = rs.ms.Unmarshal(out, dest)
|
||||
} else {
|
||||
return utils.ErrNotFound
|
||||
}
|
||||
key := utils.DESTINATION_PREFIX + destID
|
||||
if err = conn.Cmd("DEL", key).Err; err != nil {
|
||||
return err
|
||||
}
|
||||
if dest != nil {
|
||||
for _, prefix := range dest.Prefixes {
|
||||
changed := false
|
||||
if idIDs, err := cache2go.Get(utils.DESTINATION_PREFIX + prefix); err == nil {
|
||||
dIDs := idIDs.(map[interface{}]struct{})
|
||||
if len(dIDs) == 1 {
|
||||
// remove de prefix from cache
|
||||
cache2go.RemKey(utils.DESTINATION_PREFIX + prefix)
|
||||
} else {
|
||||
// delete the destination from list and put the new list in chache
|
||||
delete(dIDs, searchedDID)
|
||||
changed = true
|
||||
}
|
||||
}
|
||||
if changed {
|
||||
cache2go.Cache(utils.DESTINATION_PREFIX+prefix, dIDs)
|
||||
}
|
||||
}
|
||||
}
|
||||
dest := &Destination{Id: key}
|
||||
if historyScribe != nil {
|
||||
response := 0
|
||||
go historyScribe.Call("HistoryV1.Record", dest.GetHistoryRecord(true), &response)
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
func (rs *RedisStorage) GetActions(key string, skipCache bool) (as Actions, err error) {
|
||||
key = utils.ACTION_PREFIX + key
|
||||
if !skipCache {
|
||||
|
||||
Reference in New Issue
Block a user