From 2f76d12f37ee4ffae7917900c8fe5ff313fe013c Mon Sep 17 00:00:00 2001 From: Radu Ioan Fericean Date: Fri, 6 May 2016 13:29:49 +0300 Subject: [PATCH] added improved ApierV2 GetDestinations --- apier/v2/apier.go | 31 +++++++++++++++++++++ console/destination.go | 61 ------------------------------------------ engine/destinations.go | 1 + 3 files changed, 32 insertions(+), 61 deletions(-) delete mode 100644 console/destination.go diff --git a/apier/v2/apier.go b/apier/v2/apier.go index e337400b0..7275a6bac 100644 --- a/apier/v2/apier.go +++ b/apier/v2/apier.go @@ -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 +} diff --git a/console/destination.go b/console/destination.go deleted file mode 100644 index 1d80f1dee..000000000 --- a/console/destination.go +++ /dev/null @@ -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 -*/ - -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{} -} diff --git a/engine/destinations.go b/engine/destinations.go index c69e5be0a..5c65bd257 100644 --- a/engine/destinations.go +++ b/engine/destinations.go @@ -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