mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-11 18:16:24 +05:00
fixses for get/set destinations
This commit is contained in:
@@ -22,7 +22,7 @@ import (
|
||||
"github.com/cgrates/cgrates/rater"
|
||||
)
|
||||
|
||||
|
||||
type Apier struct {
|
||||
StorDb rater.DataStorage
|
||||
StorDb rater.DataStorage
|
||||
Getter rater.DataStorage
|
||||
}
|
||||
|
||||
@@ -51,7 +51,7 @@ type AttrDestination struct {
|
||||
}
|
||||
|
||||
func (self *Apier) GetDestination(tag string, reply *AttrDestination) error {
|
||||
if dst, err := self.StorDb.GetDestination(tag); err != nil {
|
||||
if dst, err := self.Getter.GetDestination(tag); err != nil {
|
||||
return errors.New(utils.ERR_NOT_FOUND)
|
||||
} else {
|
||||
reply.Id = dst.Id
|
||||
@@ -60,12 +60,12 @@ func (self *Apier) GetDestination(tag string, reply *AttrDestination) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (self *Apier) SetDestination(attr *AttrDestination, reply *rater.Destination) error {
|
||||
func (self *Apier) SetDestination(attr *AttrDestination, reply *float64) error {
|
||||
d := &rater.Destination{
|
||||
Id: attr.Id,
|
||||
Prefixes: attr.Prefixes,
|
||||
}
|
||||
if err := self.StorDb.SetDestination(d); err != nil {
|
||||
if err := self.Getter.SetDestination(d); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
@@ -81,7 +81,7 @@ type AttrGetBalance struct {
|
||||
// Get balance
|
||||
func (self *Apier) GetBalance(attr *AttrGetBalance, reply *float64) error {
|
||||
tag := fmt.Sprintf("%s:%s:%s", attr.Direction, attr.Tenant, attr.Account)
|
||||
userBalance, err := self.StorDb.GetUserBalance(tag)
|
||||
userBalance, err := self.Getter.GetUserBalance(tag)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -165,16 +165,16 @@ func (self *Apier) SetRatingProfile(attr *AttrSetRatingProfile, reply *float64)
|
||||
TOR: attr.TOR,
|
||||
Subject: attr.Subject,
|
||||
}
|
||||
subject, err := self.StorDb.GetRatingProfile(cd.GetKey())
|
||||
subject, err := self.Getter.GetRatingProfile(cd.GetKey())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
rp, err := self.StorDb.GetRatingProfile(attr.RatingProfileId)
|
||||
rp, err := self.Getter.GetRatingProfile(attr.RatingProfileId)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
subject.DestinationMap = rp.DestinationMap
|
||||
err = self.StorDb.SetRatingProfile(subject)
|
||||
err = self.Getter.SetRatingProfile(subject)
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -208,7 +208,7 @@ func (self *Apier) AddTriggeredAction(attr *AttrActionTrigger, reply *float64) e
|
||||
tag := fmt.Sprintf("%s:%s:%s", attr.Direction, attr.Tenant, attr.Account)
|
||||
var dbErr error
|
||||
rater.AccLock.Guard(tag, func() (float64, error) {
|
||||
userBalance, err := self.StorDb.GetUserBalance(tag)
|
||||
userBalance, err := self.Getter.GetUserBalance(tag)
|
||||
if err != nil {
|
||||
dbErr = err
|
||||
return 0, err
|
||||
@@ -216,7 +216,7 @@ func (self *Apier) AddTriggeredAction(attr *AttrActionTrigger, reply *float64) e
|
||||
|
||||
userBalance.ActionTriggers = append(userBalance.ActionTriggers, at)
|
||||
|
||||
if err = self.StorDb.SetUserBalance(userBalance); err != nil {
|
||||
if err = self.Getter.SetUserBalance(userBalance); err != nil {
|
||||
dbErr = err
|
||||
return 0, err
|
||||
}
|
||||
|
||||
@@ -22,6 +22,7 @@ import (
|
||||
"errors"
|
||||
"flag"
|
||||
"fmt"
|
||||
"github.com/cgrates/cgrates/apier"
|
||||
"github.com/cgrates/cgrates/balancer2go"
|
||||
"github.com/cgrates/cgrates/cdrs"
|
||||
"github.com/cgrates/cgrates/config"
|
||||
@@ -30,7 +31,6 @@ import (
|
||||
"github.com/cgrates/cgrates/scheduler"
|
||||
"github.com/cgrates/cgrates/sessionmanager"
|
||||
"github.com/cgrates/cgrates/utils"
|
||||
"github.com/cgrates/cgrates/apier"
|
||||
"io"
|
||||
"net"
|
||||
"net/rpc"
|
||||
@@ -64,7 +64,7 @@ var (
|
||||
err error
|
||||
)
|
||||
|
||||
func listenToRPCRequests(rpcResponder interface{}, rpcAddress string, rpc_encoding string, loggerDb rater.DataStorage) {
|
||||
func listenToRPCRequests(rpcResponder interface{}, rpcAddress string, rpc_encoding string, getter rater.DataStorage, loggerDb rater.DataStorage) {
|
||||
l, err := net.Listen("tcp", rpcAddress)
|
||||
if err != nil {
|
||||
rater.Logger.Crit(fmt.Sprintf("<Rater> Could not listen to %v: %v", rpcAddress, err))
|
||||
@@ -75,7 +75,7 @@ func listenToRPCRequests(rpcResponder interface{}, rpcAddress string, rpc_encodi
|
||||
|
||||
rater.Logger.Info(fmt.Sprintf("<Rater> Listening for incomming RPC requests on %v", l.Addr()))
|
||||
rpc.Register(rpcResponder)
|
||||
rpc.Register(&apier.Apier{StorDb:loggerDb})
|
||||
rpc.Register(&apier.Apier{StorDb: loggerDb, Getter: getter})
|
||||
var serveFunc func(io.ReadWriteCloser)
|
||||
if rpc_encoding == JSON {
|
||||
serveFunc = jsonrpc.ServeConn
|
||||
@@ -125,7 +125,7 @@ func startMediator(responder *rater.Responder, loggerDb rater.DataStorage) {
|
||||
connector = &rater.RPCClientConnector{Client: client}
|
||||
}
|
||||
var err error
|
||||
medi, err = mediator.NewMediator(connector, loggerDb, cfg )
|
||||
medi, err = mediator.NewMediator(connector, loggerDb, cfg)
|
||||
if err != nil {
|
||||
rater.Logger.Crit(fmt.Sprintf("Mediator config parsing error: %v", err))
|
||||
exitChan <- true
|
||||
@@ -187,11 +187,11 @@ func startCDRS(responder *rater.Responder, loggerDb rater.DataStorage) {
|
||||
if cfg.CDRSMediator == INTERNAL {
|
||||
for i := 0; i < 3; i++ { // ToDo: If the right approach, make the reconnects configurable
|
||||
time.Sleep(time.Duration(i/2) * time.Second)
|
||||
if medi!=nil { // Got our mediator, no need to wait any longer
|
||||
if medi != nil { // Got our mediator, no need to wait any longer
|
||||
break
|
||||
}
|
||||
}
|
||||
if medi == nil {
|
||||
if medi == nil {
|
||||
rater.Logger.Crit("<CDRS> Could not connect to mediator, exiting.")
|
||||
exitChan <- true
|
||||
}
|
||||
@@ -298,13 +298,13 @@ func main() {
|
||||
responder := &rater.Responder{ExitChan: exitChan}
|
||||
if cfg.RaterEnabled && !cfg.BalancerEnabled && cfg.RaterListen != INTERNAL {
|
||||
rater.Logger.Info(fmt.Sprintf("Starting CGRateS Rater on %s.", cfg.RaterListen))
|
||||
go listenToRPCRequests(responder, cfg.RaterListen, cfg.RPCEncoding, loggerDb)
|
||||
go listenToRPCRequests(responder, cfg.RaterListen, cfg.RPCEncoding, getter, loggerDb)
|
||||
}
|
||||
if cfg.BalancerEnabled {
|
||||
rater.Logger.Info(fmt.Sprintf("Starting CGRateS Balancer on %s.", cfg.BalancerListen))
|
||||
go stopBalancerSingnalHandler()
|
||||
responder.Bal = bal
|
||||
go listenToRPCRequests(responder, cfg.BalancerListen, cfg.RPCEncoding, loggerDb)
|
||||
go listenToRPCRequests(responder, cfg.BalancerListen, cfg.RPCEncoding, getter, loggerDb)
|
||||
if cfg.RaterEnabled {
|
||||
rater.Logger.Info("Starting internal rater.")
|
||||
bal.AddClient("local", new(rater.ResponderWorker))
|
||||
|
||||
@@ -41,12 +41,12 @@ class JSONClient(object):
|
||||
self._socket.close()
|
||||
|
||||
|
||||
rpc =JSONClient(("127.0.0.1", 2001))
|
||||
rpc =JSONClient(("127.0.0.1", 2012))
|
||||
|
||||
cd = {"Direction":"OUT", "TOR":"0", "Tenant": "vdf", "Subject": "rif", "DestinationPrefix": "0256", "TimeStart": "2012-02-02T17:30:00Z", "TimeEnd": "2012-02-02T18:30:00Z"}
|
||||
|
||||
# alternative to the above
|
||||
s = socket.create_connection(("127.0.0.1", 2001))
|
||||
s = socket.create_connection(("127.0.0.1", 2012))
|
||||
s.sendall(json.dumps(({"id": 1, "method": "Responder.GetCost", "params": [cd]})))
|
||||
print s.recv(4096)
|
||||
|
||||
|
||||
@@ -132,7 +132,7 @@ Destinations
|
||||
Prefixes []string
|
||||
}
|
||||
|
||||
**SetDestination**
|
||||
**SetTPDestination**
|
||||
Will set the prefixes for a specific destination. It will delete the existing prefixes if the destination is already in the database.
|
||||
|
||||
Parametrs:
|
||||
@@ -144,12 +144,12 @@ Dest
|
||||
A JSON string containing destination data
|
||||
|
||||
Example
|
||||
SetDestination("1dec2012", '{"Tag": "DAN_NET", "Prefixes": ["4917", "4918"]}')
|
||||
SetTPDestination("1dec2012", '{"Tag": "DAN_NET", "Prefixes": ["4917", "4918"]}')
|
||||
|
||||
Reply: '{"Reply": "ok"}'
|
||||
|
||||
|
||||
**GetDestination**
|
||||
**GetTPDestination**
|
||||
Gets a JSON destination structure.
|
||||
|
||||
Parametrs:
|
||||
@@ -161,11 +161,11 @@ Tag
|
||||
A destination tag string
|
||||
|
||||
Example
|
||||
GetDestination("1dec2012", "DAN_NET")
|
||||
GetTPDestination("1dec2012", "DAN_NET")
|
||||
|
||||
Reply: '{"Replay": {"Tag": "DAN_NET", "Prefixes": ["4917", "4918"]}}'
|
||||
|
||||
**DeleteDestination**
|
||||
**DeleteTPDestination**
|
||||
Delets a destination
|
||||
|
||||
Parametrs:
|
||||
@@ -177,11 +177,11 @@ Tag
|
||||
A destination tag string
|
||||
|
||||
Example
|
||||
DeleteDestination("1dec2012", "DAN_NET")
|
||||
DeleteTPDestination("1dec2012", "DAN_NET")
|
||||
|
||||
Replay: '{"Reply": "ok"}'
|
||||
|
||||
**GetAllDestinations**
|
||||
**GetAllTPDestinations**
|
||||
Get all destinations
|
||||
|
||||
Parametrs:
|
||||
@@ -190,7 +190,7 @@ TPid
|
||||
A string containing traiff plan id
|
||||
|
||||
Example
|
||||
GetAllDestinations("1dec2012")
|
||||
GetAllTPDestinations("1dec2012")
|
||||
|
||||
Reply: '{"Reply": [{"Tag": "DAN_NET", "Prefixes": ["4917", "4918"]}, {"Tag": "RIF_NET", "Prefixes": ["40723"]}]}'
|
||||
|
||||
@@ -208,7 +208,7 @@ Timings
|
||||
Time
|
||||
}
|
||||
|
||||
**SetTiming**
|
||||
**SetTPTiming**
|
||||
|
||||
Parametrs:
|
||||
|
||||
@@ -220,83 +220,83 @@ Timing
|
||||
|
||||
Example
|
||||
|
||||
SetTiming("1dec2012", '{"Tag": "MIDNIGHT", Year: "\*all", Months: "\*all", MonthDays: "\*all", WeekDays: "\*all", "Time": "00:00:00"}')
|
||||
SetTPTiming("1dec2012", '{"Tag": "MIDNIGHT", Year: "\*all", Months: "\*all", MonthDays: "\*all", WeekDays: "\*all", "Time": "00:00:00"}')
|
||||
|
||||
GetTiming
|
||||
GetTPTiming
|
||||
|
||||
DeleteTiming
|
||||
DeleteTPTiming
|
||||
|
||||
GetAllTimings
|
||||
GetAllTPTimings
|
||||
|
||||
|
||||
SetRate
|
||||
SetTPRate
|
||||
|
||||
GetRate
|
||||
GetTPRate
|
||||
|
||||
DeleteRate
|
||||
DeleteTPRate
|
||||
|
||||
GetAllRates
|
||||
GetAllTPRates
|
||||
|
||||
|
||||
GetRateTiming
|
||||
GetTPRateTiming
|
||||
|
||||
SetRateTiming
|
||||
SetTPRateTiming
|
||||
|
||||
DeleteRateTiming
|
||||
DeleteTPRateTiming
|
||||
|
||||
GetAllRateTinings
|
||||
GetAllTPRateTinings
|
||||
|
||||
|
||||
GetRatingProfile
|
||||
GetTPRatingProfile
|
||||
|
||||
SetRatingProfile
|
||||
SetTPRatingProfile
|
||||
|
||||
DeleteProfile
|
||||
DeleteTPProfile
|
||||
|
||||
GetAllRatingProfiles
|
||||
GetAllTPRatingProfiles
|
||||
|
||||
|
||||
GetAction
|
||||
GetTPAction
|
||||
|
||||
SetAction
|
||||
SetTPAction
|
||||
|
||||
DeleteAction
|
||||
DeleteTPAction
|
||||
|
||||
GetAllActions
|
||||
GetAllTPActions
|
||||
|
||||
|
||||
GetActionTiming
|
||||
GetTPActionTiming
|
||||
|
||||
SetActionTiming
|
||||
SetTPActionTiming
|
||||
|
||||
DeleteActionTiming
|
||||
DeleteTPActionTiming
|
||||
|
||||
GetAllActionTimings
|
||||
GetAllTPActionTimings
|
||||
|
||||
|
||||
GetActionTrigger
|
||||
GetTPActionTrigger
|
||||
|
||||
SetActionTrigger
|
||||
SetTPActionTrigger
|
||||
|
||||
DeleteActionTrigger
|
||||
DeleteTPActionTrigger
|
||||
|
||||
GetAllActionTriggers
|
||||
GetAllTPActionTriggers
|
||||
|
||||
|
||||
GetAccountAction
|
||||
GetTPAccountAction
|
||||
|
||||
SetAccountAction
|
||||
SetTPAccountAction
|
||||
|
||||
DeleteAccountAction
|
||||
DeleteTPAccountAction
|
||||
|
||||
GetAllAccountActions
|
||||
GetAllTPAccountActions
|
||||
|
||||
|
||||
ImportWithOverride
|
||||
|
||||
ImportWithFlush
|
||||
|
||||
GetAllTariffPlanIds
|
||||
GetAllTPTariffPlanIds
|
||||
|
||||
6.1.5. Management API
|
||||
---------------------
|
||||
|
||||
Reference in New Issue
Block a user