added improved ApierV2 GetDestinations

This commit is contained in:
Radu Ioan Fericean
2016-05-06 13:29:49 +03:00
parent c73016e89d
commit 2f76d12f37
3 changed files with 32 additions and 61 deletions

View File

@@ -319,3 +319,34 @@ func (self *ApierV2) GetActions(attr AttrGetActions, reply *map[string]engine.Ac
*reply = retActions
return nil
}
type AttrGetDestinations struct {
DestIDs []string
}
func (self *ApierV2) GetDestinations(attr AttrGetDestinations, reply *[]*engine.Destination) error {
dests := make([]*engine.Destination, 0)
if attr.DestIDs == nil {
return utils.NewErrMandatoryIeMissing("DestIDs")
}
if len(attr.DestIDs) == 0 {
// get all destination ids
destIDs, err := self.RatingDb.GetKeysForPrefix(utils.DESTINATION_PREFIX, true)
if err != nil {
return err
}
for _, destID := range destIDs {
attr.DestIDs = append(attr.DestIDs, destID[len(utils.DESTINATION_PREFIX):])
}
}
for _, destID := range attr.DestIDs {
dst, err := self.RatingDb.GetDestination(destID)
if err != nil {
return err
}
dests = append(dests, dst)
}
*reply = dests
return nil
}

View File

@@ -1,61 +0,0 @@
/*
Rating system designed to be used in VoIP Carriers World
Copyright (C) 2012-2015 ITsysCOM
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>
*/
package console
import "github.com/cgrates/cgrates/engine"
func init() {
c := &CmdGetDestination{
name: "destination",
rpcMethod: "ApierV1.GetDestination",
}
commands[c.Name()] = c
c.CommandExecuter = &CommandExecuter{c}
}
// Commander implementation
type CmdGetDestination struct {
name string
rpcMethod string
rpcParams *StringWrapper
*CommandExecuter
}
func (self *CmdGetDestination) Name() string {
return self.name
}
func (self *CmdGetDestination) RpcMethod() string {
return self.rpcMethod
}
func (self *CmdGetDestination) RpcParams(reset bool) interface{} {
if reset || self.rpcParams == nil {
self.rpcParams = &StringWrapper{}
}
return self.rpcParams
}
func (self *CmdGetDestination) PostprocessRpcParams() error {
return nil
}
func (self *CmdGetDestination) RpcResult() interface{} {
return &engine.Destination{}
}

View File

@@ -82,6 +82,7 @@ func CachedDestHasPrefix(destId, prefix string) bool {
}
func CleanStalePrefixes(destIds []string) {
utils.Logger.Info("Cleaning stale dest prefixes: " + utils.ToJSON(destIds))
prefixMap, err := cache2go.GetAllEntries(utils.DESTINATION_PREFIX)
if err != nil {
return