mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-11 18:16:24 +05:00
renamed timespans package to rater
This commit is contained in:
@@ -22,7 +22,7 @@ import (
|
||||
"flag"
|
||||
"fmt"
|
||||
"github.com/cgrates/cgrates/console"
|
||||
"github.com/cgrates/cgrates/timespans"
|
||||
"github.com/cgrates/cgrates/rater"
|
||||
"log"
|
||||
"net/rpc"
|
||||
"net/rpc/jsonrpc"
|
||||
@@ -38,7 +38,7 @@ var (
|
||||
func main() {
|
||||
flag.Parse()
|
||||
if *version {
|
||||
fmt.Println("CGRateS " + timespans.VERSION)
|
||||
fmt.Println("CGRateS " + rater.VERSION)
|
||||
return
|
||||
}
|
||||
var client *rpc.Client
|
||||
|
||||
@@ -21,7 +21,7 @@ package main
|
||||
import (
|
||||
"flag"
|
||||
"fmt"
|
||||
"github.com/cgrates/cgrates/timespans"
|
||||
"github.com/cgrates/cgrates/rater"
|
||||
"log"
|
||||
"path"
|
||||
"regexp"
|
||||
@@ -68,7 +68,7 @@ type validator struct {
|
||||
func main() {
|
||||
flag.Parse()
|
||||
if *version {
|
||||
fmt.Println("CGRateS " + timespans.VERSION)
|
||||
fmt.Println("CGRateS " + rater.VERSION)
|
||||
return
|
||||
}
|
||||
dataFilesValidators := []*validator{
|
||||
@@ -101,14 +101,14 @@ func main() {
|
||||
"Tenant[0-9A-Za-z_],Account[0-9A-Za-z_:.],Direction OUT|IN,ActionTimingsTag[0-9A-Za-z_],ActionTriggersTag[0-9A-Za-z_]"},
|
||||
}
|
||||
for _, v := range dataFilesValidators {
|
||||
err := timespans.ValidateCSVData(path.Join(*dataPath, v.fn), v.re)
|
||||
err := rater.ValidateCSVData(path.Join(*dataPath, v.fn), v.re)
|
||||
if err != nil {
|
||||
log.Fatal(err, "\n\t", v.message)
|
||||
}
|
||||
}
|
||||
//sep = []rune(*separator)[0]
|
||||
sep = ','
|
||||
csvr := timespans.NewFileCSVReader()
|
||||
csvr := rater.NewFileCSVReader()
|
||||
err := csvr.LoadDestinations(path.Join(*dataPath, destinationsFn), sep)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
@@ -145,7 +145,7 @@ func main() {
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
var getter timespans.DataStorage
|
||||
var getter rater.DataStorage
|
||||
switch *db_type {
|
||||
case REDIS:
|
||||
db_nb, err := strconv.Atoi(*db_name)
|
||||
@@ -155,11 +155,11 @@ func main() {
|
||||
if *db_port != "" {
|
||||
*db_host += ":" + *db_port
|
||||
}
|
||||
getter, err = timespans.NewRedisStorage(*db_host, db_nb, *db_pass)
|
||||
getter, err = rater.NewRedisStorage(*db_host, db_nb, *db_pass)
|
||||
case MONGO:
|
||||
getter, err = timespans.NewMongoStorage(*db_host, *db_port, *db_name, *db_user, *db_pass)
|
||||
getter, err = rater.NewMongoStorage(*db_host, *db_port, *db_name, *db_user, *db_pass)
|
||||
case POSTGRES:
|
||||
getter, err = timespans.NewPostgresStorage(*db_host, *db_port, *db_name, *db_user, *db_pass)
|
||||
getter, err = rater.NewPostgresStorage(*db_host, *db_port, *db_name, *db_user, *db_pass)
|
||||
default:
|
||||
log.Fatal("Unknown data db type, exiting!")
|
||||
}
|
||||
|
||||
@@ -25,9 +25,9 @@ import (
|
||||
"fmt"
|
||||
"github.com/cgrates/cgrates/balancer2go"
|
||||
"github.com/cgrates/cgrates/mediator"
|
||||
"github.com/cgrates/cgrates/rater"
|
||||
"github.com/cgrates/cgrates/scheduler"
|
||||
"github.com/cgrates/cgrates/sessionmanager"
|
||||
"github.com/cgrates/cgrates/timespans"
|
||||
"io"
|
||||
"net"
|
||||
"net/rpc"
|
||||
@@ -166,13 +166,13 @@ func readConfig(c *conf.ConfigFile) {
|
||||
func listenToRPCRequests(rpcResponder interface{}, rpcAddress string, rpc_encoding string) {
|
||||
l, err := net.Listen("tcp", rpcAddress)
|
||||
if err != nil {
|
||||
timespans.Logger.Crit(fmt.Sprintf("Could not listen to %v: %v", rpcAddress, err))
|
||||
rater.Logger.Crit(fmt.Sprintf("Could not listen to %v: %v", rpcAddress, err))
|
||||
exitChan <- true
|
||||
return
|
||||
}
|
||||
defer l.Close()
|
||||
|
||||
timespans.Logger.Info(fmt.Sprintf("Listening for incomming RPC requests on %v", l.Addr()))
|
||||
rater.Logger.Info(fmt.Sprintf("Listening for incomming RPC requests on %v", l.Addr()))
|
||||
rpc.Register(rpcResponder)
|
||||
var serveFunc func(io.ReadWriteCloser)
|
||||
if rpc_encoding == JSON {
|
||||
@@ -183,17 +183,17 @@ func listenToRPCRequests(rpcResponder interface{}, rpcAddress string, rpc_encodi
|
||||
for {
|
||||
conn, err := l.Accept()
|
||||
if err != nil {
|
||||
timespans.Logger.Err(fmt.Sprintf("accept error: %v", conn))
|
||||
rater.Logger.Err(fmt.Sprintf("accept error: %v", conn))
|
||||
continue
|
||||
}
|
||||
|
||||
timespans.Logger.Info(fmt.Sprintf("connection started: %v", conn.RemoteAddr()))
|
||||
rater.Logger.Info(fmt.Sprintf("connection started: %v", conn.RemoteAddr()))
|
||||
go serveFunc(conn)
|
||||
}
|
||||
}
|
||||
|
||||
func startMediator(responder *timespans.Responder, loggerDb timespans.DataStorage) {
|
||||
var connector timespans.Connector
|
||||
func startMediator(responder *rater.Responder, loggerDb rater.DataStorage) {
|
||||
var connector rater.Connector
|
||||
if mediator_rater == INTERNAL {
|
||||
connector = responder
|
||||
} else {
|
||||
@@ -205,22 +205,22 @@ func startMediator(responder *timespans.Responder, loggerDb timespans.DataStorag
|
||||
client, err = rpc.Dial("tcp", mediator_rater)
|
||||
}
|
||||
if err != nil {
|
||||
timespans.Logger.Crit(fmt.Sprintf("Could not connect to rater: %v", err))
|
||||
rater.Logger.Crit(fmt.Sprintf("Could not connect to rater: %v", err))
|
||||
exitChan <- true
|
||||
}
|
||||
connector = ×pans.RPCClientConnector{Client: client}
|
||||
connector = &rater.RPCClientConnector{Client: client}
|
||||
}
|
||||
if _, err := os.Stat(mediator_cdr_path); err != nil {
|
||||
timespans.Logger.Crit(fmt.Sprintf("The input path for mediator does not exist: %v", mediator_cdr_path))
|
||||
rater.Logger.Crit(fmt.Sprintf("The input path for mediator does not exist: %v", mediator_cdr_path))
|
||||
exitChan <- true
|
||||
}
|
||||
if _, err := os.Stat(mediator_cdr_out_path); err != nil {
|
||||
timespans.Logger.Crit(fmt.Sprintf("The output path for mediator does not exist: %v", mediator_cdr_out_path))
|
||||
rater.Logger.Crit(fmt.Sprintf("The output path for mediator does not exist: %v", mediator_cdr_out_path))
|
||||
exitChan <- true
|
||||
}
|
||||
// Check parsing errors
|
||||
if cfgParseErr != nil {
|
||||
timespans.Logger.Crit(fmt.Sprintf("Errors on config parsing: <%v>", cfgParseErr))
|
||||
rater.Logger.Crit(fmt.Sprintf("Errors on config parsing: <%v>", cfgParseErr))
|
||||
exitChan <- true
|
||||
}
|
||||
|
||||
@@ -228,15 +228,15 @@ func startMediator(responder *timespans.Responder, loggerDb timespans.DataStorag
|
||||
freeswitch_tor, freeswitch_tenant, freeswitch_subject, freeswitch_account, freeswitch_destination,
|
||||
freeswitch_time_start, freeswitch_duration, freeswitch_uuid)
|
||||
if err != nil {
|
||||
timespans.Logger.Crit(fmt.Sprintf("Mediator config parsing error: %v", err))
|
||||
rater.Logger.Crit(fmt.Sprintf("Mediator config parsing error: %v", err))
|
||||
exitChan <- true
|
||||
}
|
||||
|
||||
m.TrackCDRFiles(mediator_cdr_path)
|
||||
}
|
||||
|
||||
func startSessionManager(responder *timespans.Responder, loggerDb timespans.DataStorage) {
|
||||
var connector timespans.Connector
|
||||
func startSessionManager(responder *rater.Responder, loggerDb rater.DataStorage) {
|
||||
var connector rater.Connector
|
||||
if sm_rater == INTERNAL {
|
||||
connector = responder
|
||||
} else {
|
||||
@@ -248,10 +248,10 @@ func startSessionManager(responder *timespans.Responder, loggerDb timespans.Data
|
||||
client, err = rpc.Dial("tcp", sm_rater)
|
||||
}
|
||||
if err != nil {
|
||||
timespans.Logger.Crit(fmt.Sprintf("Could not connect to rater: %v", err))
|
||||
rater.Logger.Crit(fmt.Sprintf("Could not connect to rater: %v", err))
|
||||
exitChan <- true
|
||||
}
|
||||
connector = ×pans.RPCClientConnector{Client: client}
|
||||
connector = &rater.RPCClientConnector{Client: client}
|
||||
}
|
||||
switch sm_switch_type {
|
||||
case FS:
|
||||
@@ -259,18 +259,18 @@ func startSessionManager(responder *timespans.Responder, loggerDb timespans.Data
|
||||
dp, _ := time.ParseDuration(fmt.Sprintf("%vs", sm_debit_period))
|
||||
sm.Connect(&sessionmanager.SessionDelegate{Connector: connector, DebitPeriod: dp}, freeswitch_server, freeswitch_pass)
|
||||
default:
|
||||
timespans.Logger.Err(fmt.Sprintf("Cannot start session manger of type: %s!", sm_switch_type))
|
||||
rater.Logger.Err(fmt.Sprintf("Cannot start session manger of type: %s!", sm_switch_type))
|
||||
exitChan <- true
|
||||
}
|
||||
}
|
||||
|
||||
func checkConfigSanity() {
|
||||
if sm_enabled && rater_enabled && rater_balancer != DISABLED {
|
||||
timespans.Logger.Crit("The session manager must not be enabled on a worker rater (change [rater]/balancer to disabled)!")
|
||||
rater.Logger.Crit("The session manager must not be enabled on a worker rater (change [rater]/balancer to disabled)!")
|
||||
exitChan <- true
|
||||
}
|
||||
if balancer_enabled && rater_enabled && rater_balancer != DISABLED {
|
||||
timespans.Logger.Crit("The balancer is enabled so it cannot connect to anatoher balancer (change [rater]/balancer to disabled)!")
|
||||
rater.Logger.Crit("The balancer is enabled so it cannot connect to anatoher balancer (change [rater]/balancer to disabled)!")
|
||||
exitChan <- true
|
||||
}
|
||||
|
||||
@@ -281,13 +281,13 @@ func checkConfigSanity() {
|
||||
if strings.Contains(sm_rater, "localhost") || strings.Contains(sm_rater, "127.0.0.1") {
|
||||
if balancer_enabled {
|
||||
if balancer_rpc_encoding != sm_rpc_encoding {
|
||||
timespans.Logger.Crit("If you are connecting the session manager via the loopback to the balancer use the same type of rpc encoding!")
|
||||
rater.Logger.Crit("If you are connecting the session manager via the loopback to the balancer use the same type of rpc encoding!")
|
||||
exitChan <- true
|
||||
}
|
||||
}
|
||||
if rater_enabled {
|
||||
if rater_rpc_encoding != sm_rpc_encoding {
|
||||
timespans.Logger.Crit("If you are connecting the session manager via the loopback to the arter use the same type of rpc encoding!")
|
||||
rater.Logger.Crit("If you are connecting the session manager via the loopback to the arter use the same type of rpc encoding!")
|
||||
exitChan <- true
|
||||
}
|
||||
}
|
||||
@@ -295,44 +295,44 @@ func checkConfigSanity() {
|
||||
if strings.Contains(mediator_rater, "localhost") || strings.Contains(mediator_rater, "127.0.0.1") {
|
||||
if balancer_enabled {
|
||||
if balancer_rpc_encoding != mediator_rpc_encoding {
|
||||
timespans.Logger.Crit("If you are connecting the mediator via the loopback to the balancer use the same type of rpc encoding!")
|
||||
rater.Logger.Crit("If you are connecting the mediator via the loopback to the balancer use the same type of rpc encoding!")
|
||||
exitChan <- true
|
||||
}
|
||||
}
|
||||
if rater_enabled {
|
||||
if rater_rpc_encoding != mediator_rpc_encoding {
|
||||
timespans.Logger.Crit("If you are connecting the mediator via the loopback to the arter use the same type of rpc encoding!")
|
||||
rater.Logger.Crit("If you are connecting the mediator via the loopback to the arter use the same type of rpc encoding!")
|
||||
exitChan <- true
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func configureDatabase(db_type, host, port, name, user, pass string) (getter timespans.DataStorage, err error) {
|
||||
func configureDatabase(db_type, host, port, name, user, pass string) (getter rater.DataStorage, err error) {
|
||||
|
||||
switch db_type {
|
||||
case REDIS:
|
||||
db_nb, err := strconv.Atoi(name)
|
||||
if err != nil {
|
||||
timespans.Logger.Crit("Redis db name must be an integer!")
|
||||
rater.Logger.Crit("Redis db name must be an integer!")
|
||||
exitChan <- true
|
||||
}
|
||||
if port != "" {
|
||||
host += ":" + port
|
||||
}
|
||||
getter, err = timespans.NewRedisStorage(host, db_nb, pass)
|
||||
getter, err = rater.NewRedisStorage(host, db_nb, pass)
|
||||
case MONGO:
|
||||
getter, err = timespans.NewMongoStorage(host, port, name, user, pass)
|
||||
getter, err = rater.NewMongoStorage(host, port, name, user, pass)
|
||||
case POSTGRES:
|
||||
getter, err = timespans.NewPostgresStorage(host, port, name, user, pass)
|
||||
getter, err = rater.NewPostgresStorage(host, port, name, user, pass)
|
||||
default:
|
||||
err = errors.New("unknown db")
|
||||
timespans.Logger.Crit("Unknown db type, exiting!")
|
||||
rater.Logger.Crit("Unknown db type, exiting!")
|
||||
exitChan <- true
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
timespans.Logger.Crit(fmt.Sprintf("Could not connect to db: %v, exiting!", err))
|
||||
rater.Logger.Crit(fmt.Sprintf("Could not connect to db: %v, exiting!", err))
|
||||
exitChan <- true
|
||||
}
|
||||
return
|
||||
@@ -341,25 +341,25 @@ func configureDatabase(db_type, host, port, name, user, pass string) (getter tim
|
||||
func main() {
|
||||
flag.Parse()
|
||||
if *version {
|
||||
fmt.Println("CGRateS " + timespans.VERSION)
|
||||
fmt.Println("CGRateS " + rater.VERSION)
|
||||
return
|
||||
}
|
||||
runtime.GOMAXPROCS(runtime.NumCPU())
|
||||
c, err := conf.ReadConfigFile(*config)
|
||||
if err != nil {
|
||||
timespans.Logger.Err(fmt.Sprintf("Could not open the configuration file: %v", err))
|
||||
rater.Logger.Err(fmt.Sprintf("Could not open the configuration file: %v", err))
|
||||
return
|
||||
}
|
||||
readConfig(c)
|
||||
// some consitency checks
|
||||
go checkConfigSanity()
|
||||
|
||||
var getter, loggerDb timespans.DataStorage
|
||||
var getter, loggerDb rater.DataStorage
|
||||
getter, err = configureDatabase(data_db_type, data_db_host, data_db_port, data_db_name, data_db_user, data_db_pass)
|
||||
|
||||
if err == nil {
|
||||
defer getter.Close()
|
||||
timespans.SetDataStorage(getter)
|
||||
rater.SetDataStorage(getter)
|
||||
}
|
||||
|
||||
if log_db_type == SAME {
|
||||
@@ -369,12 +369,12 @@ func main() {
|
||||
}
|
||||
if err == nil {
|
||||
defer loggerDb.Close()
|
||||
timespans.SetStorageLogger(loggerDb)
|
||||
rater.SetStorageLogger(loggerDb)
|
||||
}
|
||||
|
||||
if sm_debit_period > 0 {
|
||||
if dp, err := time.ParseDuration(fmt.Sprintf("%vs", sm_debit_period)); err == nil {
|
||||
timespans.SetDebitPeriod(dp)
|
||||
rater.SetDebitPeriod(dp)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -382,24 +382,24 @@ func main() {
|
||||
go registerToBalancer()
|
||||
go stopRaterSingnalHandler()
|
||||
}
|
||||
responder := ×pans.Responder{ExitChan: exitChan}
|
||||
responder := &rater.Responder{ExitChan: exitChan}
|
||||
if rater_enabled && !balancer_enabled && rater_listen != INTERNAL {
|
||||
timespans.Logger.Info(fmt.Sprintf("Starting CGRateS rater on %s.", rater_listen))
|
||||
rater.Logger.Info(fmt.Sprintf("Starting CGRateS rater on %s.", rater_listen))
|
||||
go listenToRPCRequests(responder, rater_listen, rater_rpc_encoding)
|
||||
}
|
||||
if balancer_enabled {
|
||||
timespans.Logger.Info(fmt.Sprintf("Starting CGRateS balancer on %s.", balancer_listen))
|
||||
rater.Logger.Info(fmt.Sprintf("Starting CGRateS balancer on %s.", balancer_listen))
|
||||
go stopBalancerSingnalHandler()
|
||||
responder.Bal = bal
|
||||
go listenToRPCRequests(responder, balancer_listen, balancer_rpc_encoding)
|
||||
if rater_enabled {
|
||||
timespans.Logger.Info("Starting internal rater.")
|
||||
bal.AddClient("local", new(timespans.ResponderWorker))
|
||||
rater.Logger.Info("Starting internal rater.")
|
||||
bal.AddClient("local", new(rater.ResponderWorker))
|
||||
}
|
||||
}
|
||||
|
||||
if scheduler_enabled {
|
||||
timespans.Logger.Info("Starting CGRateS scheduler.")
|
||||
rater.Logger.Info("Starting CGRateS scheduler.")
|
||||
go func() {
|
||||
sched := scheduler.NewScheduler()
|
||||
go reloadSchedulerSingnalHandler(sched, getter)
|
||||
@@ -409,12 +409,12 @@ func main() {
|
||||
}
|
||||
|
||||
if sm_enabled {
|
||||
timespans.Logger.Info("Starting CGRateS session manager.")
|
||||
rater.Logger.Info("Starting CGRateS session manager.")
|
||||
go startSessionManager(responder, loggerDb)
|
||||
}
|
||||
|
||||
if mediator_enabled {
|
||||
timespans.Logger.Info("Starting CGRateS mediator.")
|
||||
rater.Logger.Info("Starting CGRateS mediator.")
|
||||
go startMediator(responder, loggerDb)
|
||||
}
|
||||
|
||||
|
||||
@@ -20,8 +20,8 @@ package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/cgrates/cgrates/rater"
|
||||
"github.com/cgrates/cgrates/scheduler"
|
||||
"github.com/cgrates/cgrates/timespans"
|
||||
"net/rpc"
|
||||
"os"
|
||||
"os/signal"
|
||||
@@ -32,12 +32,12 @@ import (
|
||||
Listens for SIGTERM, SIGINT, SIGQUIT system signals and shuts down all the registered raters.
|
||||
*/
|
||||
func stopBalancerSingnalHandler() {
|
||||
timespans.Logger.Info("Handling stop signals...")
|
||||
rater.Logger.Info("Handling stop signals...")
|
||||
c := make(chan os.Signal)
|
||||
signal.Notify(c, syscall.SIGTERM, syscall.SIGINT, syscall.SIGQUIT)
|
||||
|
||||
sig := <-c
|
||||
timespans.Logger.Info(fmt.Sprintf("Caught signal %v, sending shutdownto raters\n", sig))
|
||||
rater.Logger.Info(fmt.Sprintf("Caught signal %v, sending shutdownto raters\n", sig))
|
||||
bal.Shutdown("Responder.Shutdown")
|
||||
exitChan <- true
|
||||
}
|
||||
@@ -46,12 +46,12 @@ func stopBalancerSingnalHandler() {
|
||||
Listens for the SIGTERM, SIGINT, SIGQUIT system signals and gracefuly unregister from balancer and closes the storage before exiting.
|
||||
*/
|
||||
func stopRaterSingnalHandler() {
|
||||
timespans.Logger.Info("Handling stop signals...")
|
||||
rater.Logger.Info("Handling stop signals...")
|
||||
c := make(chan os.Signal)
|
||||
signal.Notify(c, syscall.SIGTERM, syscall.SIGINT, syscall.SIGQUIT)
|
||||
sig := <-c
|
||||
|
||||
timespans.Logger.Info(fmt.Sprintf("Caught signal %v, unregistering from balancer\n", sig))
|
||||
rater.Logger.Info(fmt.Sprintf("Caught signal %v, unregistering from balancer\n", sig))
|
||||
unregisterFromBalancer()
|
||||
exitChan <- true
|
||||
}
|
||||
@@ -62,15 +62,15 @@ Connects to the balancer and calls unregister RPC method.
|
||||
func unregisterFromBalancer() {
|
||||
client, err := rpc.Dial("tcp", rater_balancer)
|
||||
if err != nil {
|
||||
timespans.Logger.Crit("Cannot contact the balancer!")
|
||||
rater.Logger.Crit("Cannot contact the balancer!")
|
||||
exitChan <- true
|
||||
return
|
||||
}
|
||||
var reply int
|
||||
timespans.Logger.Info(fmt.Sprintf("Unregistering from balancer %s", rater_balancer))
|
||||
rater.Logger.Info(fmt.Sprintf("Unregistering from balancer %s", rater_balancer))
|
||||
client.Call("Responder.UnRegisterRater", rater_listen, &reply)
|
||||
if err := client.Close(); err != nil {
|
||||
timespans.Logger.Crit("Could not close balancer unregistration!")
|
||||
rater.Logger.Crit("Could not close balancer unregistration!")
|
||||
exitChan <- true
|
||||
}
|
||||
}
|
||||
@@ -81,29 +81,29 @@ Connects to the balancer and rehisters the rater to the server.
|
||||
func registerToBalancer() {
|
||||
client, err := rpc.Dial("tcp", rater_balancer)
|
||||
if err != nil {
|
||||
timespans.Logger.Crit(fmt.Sprintf("Cannot contact the balancer: %v", err))
|
||||
rater.Logger.Crit(fmt.Sprintf("Cannot contact the balancer: %v", err))
|
||||
exitChan <- true
|
||||
return
|
||||
}
|
||||
var reply int
|
||||
timespans.Logger.Info(fmt.Sprintf("Registering to balancer %s", rater_balancer))
|
||||
rater.Logger.Info(fmt.Sprintf("Registering to balancer %s", rater_balancer))
|
||||
client.Call("Responder.RegisterRater", rater_listen, &reply)
|
||||
if err := client.Close(); err != nil {
|
||||
timespans.Logger.Crit("Could not close balancer registration!")
|
||||
rater.Logger.Crit("Could not close balancer registration!")
|
||||
exitChan <- true
|
||||
}
|
||||
timespans.Logger.Info("Registration finished!")
|
||||
rater.Logger.Info("Registration finished!")
|
||||
}
|
||||
|
||||
// Listens for the HUP system signal and gracefuly reloads the timers from database.
|
||||
func reloadSchedulerSingnalHandler(sched *scheduler.Scheduler, getter timespans.DataStorage) {
|
||||
timespans.Logger.Info("Handling HUP signal...")
|
||||
func reloadSchedulerSingnalHandler(sched *scheduler.Scheduler, getter rater.DataStorage) {
|
||||
rater.Logger.Info("Handling HUP signal...")
|
||||
for {
|
||||
c := make(chan os.Signal)
|
||||
signal.Notify(c, syscall.SIGHUP)
|
||||
sig := <-c
|
||||
|
||||
timespans.Logger.Info(fmt.Sprintf("Caught signal %v, reloading action timings.\n", sig))
|
||||
rater.Logger.Info(fmt.Sprintf("Caught signal %v, reloading action timings.\n", sig))
|
||||
sched.LoadActionTimings(getter)
|
||||
// check the tip of the queue for new actions
|
||||
sched.Restart()
|
||||
|
||||
@@ -20,7 +20,7 @@ package main
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"github.com/cgrates/cgrates/timespans"
|
||||
"github.com/cgrates/cgrates/rater"
|
||||
"log"
|
||||
"net/rpc"
|
||||
//"net/rpc/jsonrpc"
|
||||
@@ -42,8 +42,8 @@ func main() {
|
||||
|
||||
t1 := time.Date(2012, time.February, 02, 17, 30, 0, 0, time.UTC)
|
||||
t2 := time.Date(2012, time.February, 02, 18, 30, 0, 0, time.UTC)
|
||||
cd := timespans.CallDescriptor{Direction: "OUT", TOR: "0", Tenant: "vdf", Subject: "rif", Destination: "0256", TimeStart: t1, TimeEnd: t2}
|
||||
result := timespans.CallCost{}
|
||||
cd := rater.CallDescriptor{Direction: "OUT", TOR: "0", Tenant: "vdf", Subject: "rif", Destination: "0256", TimeStart: t1, TimeEnd: t2}
|
||||
result := rater.CallCost{}
|
||||
var client *rpc.Client
|
||||
var err error
|
||||
if *json {
|
||||
|
||||
@@ -20,7 +20,7 @@ package main
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"github.com/cgrates/cgrates/timespans"
|
||||
"github.com/cgrates/cgrates/rater"
|
||||
"log"
|
||||
"os"
|
||||
"runtime"
|
||||
@@ -57,16 +57,16 @@ func main() {
|
||||
}
|
||||
t1 := time.Date(2012, time.February, 02, 17, 30, 0, 0, time.UTC)
|
||||
t2 := time.Date(2012, time.February, 02, 18, 30, 0, 0, time.UTC)
|
||||
cd := timespans.CallDescriptor{Direction: "OUT", TOR: "0", Tenant: "vdf", Subject: "rif", Destination: "0256", TimeStart: t1, TimeEnd: t2}
|
||||
cd := rater.CallDescriptor{Direction: "OUT", TOR: "0", Tenant: "vdf", Subject: "rif", Destination: "0256", TimeStart: t1, TimeEnd: t2}
|
||||
|
||||
getter, err := timespans.NewRedisStorage("", 10, "")
|
||||
//getter, err := timespans.NewMongoStorage("localhost", "cgrates")
|
||||
getter, err := rater.NewRedisStorage("", 10, "")
|
||||
//getter, err := rater.NewMongoStorage("localhost", "cgrates")
|
||||
defer getter.Close()
|
||||
|
||||
timespans.SetDataStorage(getter)
|
||||
rater.SetDataStorage(getter)
|
||||
|
||||
log.Printf("Runnning %d cycles...", *runs)
|
||||
var result *timespans.CallCost
|
||||
var result *rater.CallCost
|
||||
j := 0
|
||||
start := time.Now()
|
||||
for i := 0; i < *runs; i++ {
|
||||
|
||||
@@ -24,7 +24,7 @@ import (
|
||||
"flag"
|
||||
"fmt"
|
||||
"github.com/cgrates/cgrates/inotify"
|
||||
"github.com/cgrates/cgrates/timespans"
|
||||
"github.com/cgrates/cgrates/rater"
|
||||
"os"
|
||||
"path"
|
||||
"strconv"
|
||||
@@ -51,8 +51,8 @@ func (mfi *mediatorFieldIdxs) Load(idxs string) error {
|
||||
}
|
||||
|
||||
type Mediator struct {
|
||||
connector timespans.Connector
|
||||
loggerDb timespans.DataStorage
|
||||
connector rater.Connector
|
||||
loggerDb rater.DataStorage
|
||||
skipDb bool
|
||||
outputDir string
|
||||
pseudoPrepaid bool
|
||||
@@ -68,8 +68,8 @@ type Mediator struct {
|
||||
}
|
||||
|
||||
// Creates a new mediator object parsing the indexses
|
||||
func NewMediator(connector timespans.Connector,
|
||||
loggerDb timespans.DataStorage,
|
||||
func NewMediator(connector rater.Connector,
|
||||
loggerDb rater.DataStorage,
|
||||
skipDb bool,
|
||||
outputDir string,
|
||||
pseudoPrepaid bool,
|
||||
@@ -120,19 +120,19 @@ func (m *Mediator) TrackCDRFiles(cdrPath string) (err error) {
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
timespans.Logger.Info(fmt.Sprintf("Monitoring %v for file moves.", cdrPath))
|
||||
rater.Logger.Info(fmt.Sprintf("Monitoring %v for file moves.", cdrPath))
|
||||
for {
|
||||
select {
|
||||
case ev := <-watcher.Event:
|
||||
if ev.Mask&inotify.IN_MOVED_TO != 0 {
|
||||
timespans.Logger.Info(fmt.Sprintf("Started to parse %v", ev.Name))
|
||||
rater.Logger.Info(fmt.Sprintf("Started to parse %v", ev.Name))
|
||||
err = m.parseCSV(ev.Name)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
case err := <-watcher.Error:
|
||||
timespans.Logger.Err(fmt.Sprintf("Inotify error: %v", err))
|
||||
rater.Logger.Err(fmt.Sprintf("Inotify error: %v", err))
|
||||
}
|
||||
}
|
||||
return
|
||||
@@ -144,7 +144,7 @@ func (m *Mediator) parseCSV(cdrfn string) (err error) {
|
||||
file, err := os.Open(cdrfn)
|
||||
defer file.Close()
|
||||
if err != nil {
|
||||
timespans.Logger.Crit(err.Error())
|
||||
rater.Logger.Crit(err.Error())
|
||||
os.Exit(1)
|
||||
}
|
||||
csvReader := csv.NewReader(bufio.NewReader(file))
|
||||
@@ -160,7 +160,7 @@ func (m *Mediator) parseCSV(cdrfn string) (err error) {
|
||||
|
||||
for record, ok := csvReader.Read(); ok == nil; record, ok = csvReader.Read() {
|
||||
//t, _ := time.Parse("2012-05-21 17:48:20", record[5])
|
||||
var cc *timespans.CallCost
|
||||
var cc *rater.CallCost
|
||||
for runIdx := range m.subjectIndexs { // Query costs for every run index given by subject
|
||||
if runIdx == 0 && !m.skipDb { // The first index is matching the session manager one
|
||||
cc, err = m.getCostsFromDB(record, runIdx)
|
||||
@@ -172,10 +172,10 @@ func (m *Mediator) parseCSV(cdrfn string) (err error) {
|
||||
}
|
||||
cost := "-1"
|
||||
if err != nil {
|
||||
timespans.Logger.Err(fmt.Sprintf("Could not get the cost for mediator record with uuid:%s and subject:%s - %s", record[m.uuidIndexs[runIdx]], record[m.subjectIndexs[runIdx]], err.Error()))
|
||||
rater.Logger.Err(fmt.Sprintf("Could not get the cost for mediator record with uuid:%s and subject:%s - %s", record[m.uuidIndexs[runIdx]], record[m.subjectIndexs[runIdx]], err.Error()))
|
||||
} else {
|
||||
cost = strconv.FormatFloat(cc.ConnectFee+cc.Cost, 'f', -1, 64)
|
||||
timespans.Logger.Debug(fmt.Sprintf("Calculated for uuid:%s, subject:%s cost: %v", record[m.uuidIndexs[runIdx]], record[m.subjectIndexs[runIdx]], cost))
|
||||
rater.Logger.Debug(fmt.Sprintf("Calculated for uuid:%s, subject:%s cost: %v", record[m.uuidIndexs[runIdx]], record[m.subjectIndexs[runIdx]], cost))
|
||||
}
|
||||
record = append(record, cost)
|
||||
}
|
||||
@@ -186,20 +186,20 @@ func (m *Mediator) parseCSV(cdrfn string) (err error) {
|
||||
}
|
||||
|
||||
// Retrive the cost from logging database
|
||||
func (m *Mediator) getCostsFromDB(record []string, runIdx int) (cc *timespans.CallCost, err error) {
|
||||
func (m *Mediator) getCostsFromDB(record []string, runIdx int) (cc *rater.CallCost, err error) {
|
||||
searchedUUID := record[m.uuidIndexs[runIdx]]
|
||||
cc, err = m.loggerDb.GetCallCostLog(searchedUUID, timespans.SESSION_MANAGER_SOURCE)
|
||||
cc, err = m.loggerDb.GetCallCostLog(searchedUUID, rater.SESSION_MANAGER_SOURCE)
|
||||
return
|
||||
}
|
||||
|
||||
// Retrive the cost from rater
|
||||
func (m *Mediator) getCostsFromRater(record []string, runIdx int) (cc *timespans.CallCost, err error) {
|
||||
func (m *Mediator) getCostsFromRater(record []string, runIdx int) (cc *rater.CallCost, err error) {
|
||||
d, err := time.ParseDuration(record[m.durationIndexs[runIdx]] + "s")
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
cc = ×pans.CallCost{}
|
||||
cc = &rater.CallCost{}
|
||||
if d.Seconds() == 0 { // failed call, returning empty callcost, no error
|
||||
return cc, nil
|
||||
}
|
||||
@@ -207,7 +207,7 @@ func (m *Mediator) getCostsFromRater(record []string, runIdx int) (cc *timespans
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
cd := timespans.CallDescriptor{
|
||||
cd := rater.CallDescriptor{
|
||||
Direction: "OUT", //record[m.directionIndexs[runIdx]] TODO: fix me
|
||||
Tenant: record[m.tenantIndexs[runIdx]],
|
||||
TOR: record[m.torIndexs[runIdx]],
|
||||
@@ -222,9 +222,9 @@ func (m *Mediator) getCostsFromRater(record []string, runIdx int) (cc *timespans
|
||||
err = m.connector.GetCost(cd, cc)
|
||||
}
|
||||
if err != nil {
|
||||
m.loggerDb.LogError(record[m.uuidIndexs[runIdx]], timespans.MEDIATOR_SOURCE, err.Error())
|
||||
m.loggerDb.LogError(record[m.uuidIndexs[runIdx]], rater.MEDIATOR_SOURCE, err.Error())
|
||||
} else {
|
||||
m.loggerDb.LogCallCost(record[m.uuidIndexs[runIdx]], timespans.MEDIATOR_SOURCE, cc)
|
||||
m.loggerDb.LogCallCost(record[m.uuidIndexs[runIdx]], rater.MEDIATOR_SOURCE, cc)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@ 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 timespans
|
||||
package rater
|
||||
|
||||
import (
|
||||
"sync"
|
||||
@@ -16,7 +16,7 @@ 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 timespans
|
||||
package rater
|
||||
|
||||
import (
|
||||
"testing"
|
||||
@@ -16,7 +16,7 @@ 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 timespans
|
||||
package rater
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
@@ -16,7 +16,7 @@ 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 timespans
|
||||
package rater
|
||||
|
||||
import (
|
||||
"crypto/rand"
|
||||
@@ -16,7 +16,7 @@ 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 timespans
|
||||
package rater
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
@@ -16,7 +16,7 @@ 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 timespans
|
||||
package rater
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
@@ -16,7 +16,7 @@ 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 timespans
|
||||
package rater
|
||||
|
||||
import (
|
||||
"github.com/cgrates/cgrates/cache2go"
|
||||
@@ -16,7 +16,7 @@ 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 timespans
|
||||
package rater
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
@@ -15,7 +15,7 @@ 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 timespans
|
||||
package rater
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
@@ -16,7 +16,7 @@ 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 timespans
|
||||
package rater
|
||||
|
||||
import (
|
||||
// "log"
|
||||
@@ -16,7 +16,7 @@ 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 timespans
|
||||
package rater
|
||||
|
||||
import (
|
||||
"errors"
|
||||
@@ -16,7 +16,7 @@ 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 timespans
|
||||
package rater
|
||||
|
||||
import (
|
||||
"testing"
|
||||
@@ -16,7 +16,7 @@ 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 timespans
|
||||
package rater
|
||||
|
||||
import (
|
||||
"encoding/csv"
|
||||
@@ -16,7 +16,7 @@ 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 timespans
|
||||
package rater
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
@@ -16,7 +16,7 @@ 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 timespans
|
||||
package rater
|
||||
|
||||
import (
|
||||
"testing"
|
||||
@@ -16,7 +16,7 @@ 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 timespans
|
||||
package rater
|
||||
|
||||
import (
|
||||
// "log"
|
||||
@@ -16,7 +16,7 @@ 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 timespans
|
||||
package rater
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
@@ -16,7 +16,7 @@ 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 timespans
|
||||
package rater
|
||||
|
||||
import (
|
||||
"github.com/cgrates/cgrates/cache2go"
|
||||
@@ -16,7 +16,7 @@ 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 timespans
|
||||
package rater
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
@@ -16,7 +16,7 @@ You should have received a copy of the GNU General Public License
|
||||
along with thresult program. If not, see <http://www.gnu.org/licenses/>
|
||||
*/
|
||||
|
||||
package timespans
|
||||
package rater
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
@@ -16,7 +16,7 @@ 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 timespans
|
||||
package rater
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
@@ -16,7 +16,7 @@ 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 timespans
|
||||
package rater
|
||||
|
||||
import (
|
||||
"log"
|
||||
@@ -16,7 +16,7 @@ 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 timespans
|
||||
package rater
|
||||
|
||||
import (
|
||||
"math"
|
||||
@@ -16,7 +16,7 @@ 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 timespans
|
||||
package rater
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
@@ -16,7 +16,7 @@ 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 timespans
|
||||
package rater
|
||||
|
||||
import (
|
||||
"errors"
|
||||
@@ -16,7 +16,7 @@ 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 timespans
|
||||
package rater
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
@@ -16,7 +16,7 @@ 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 timespans
|
||||
package rater
|
||||
|
||||
import (
|
||||
"errors"
|
||||
@@ -16,7 +16,7 @@ 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 timespans
|
||||
package rater
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
@@ -16,7 +16,7 @@ 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 timespans
|
||||
package rater
|
||||
|
||||
import (
|
||||
"errors"
|
||||
@@ -16,7 +16,7 @@ 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 timespans
|
||||
package rater
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
@@ -16,7 +16,7 @@ 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 timespans
|
||||
package rater
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
@@ -16,7 +16,7 @@ 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 timespans
|
||||
package rater
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
@@ -16,7 +16,7 @@ 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 timespans
|
||||
package rater
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
@@ -16,7 +16,7 @@ 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 timespans
|
||||
package rater
|
||||
|
||||
import (
|
||||
"testing"
|
||||
@@ -16,7 +16,7 @@ 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 timespans
|
||||
package rater
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
@@ -16,7 +16,7 @@ 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 timespans
|
||||
package rater
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
@@ -16,7 +16,7 @@ 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 timespans
|
||||
package rater
|
||||
|
||||
import (
|
||||
"errors"
|
||||
@@ -16,7 +16,7 @@ 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 timespans
|
||||
package rater
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
@@ -20,13 +20,13 @@ package scheduler
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/cgrates/cgrates/timespans"
|
||||
"github.com/cgrates/cgrates/rater"
|
||||
"sort"
|
||||
"time"
|
||||
)
|
||||
|
||||
type Scheduler struct {
|
||||
queue timespans.ActionTimingPriotityList
|
||||
queue rater.ActionTimingPriotityList
|
||||
timer *time.Timer
|
||||
restartLoop chan bool
|
||||
}
|
||||
@@ -43,19 +43,19 @@ func (s *Scheduler) Loop() {
|
||||
a0 := s.queue[0]
|
||||
now := time.Now()
|
||||
if a0.GetNextStartTime().Equal(now) || a0.GetNextStartTime().Before(now) {
|
||||
timespans.Logger.Debug(fmt.Sprintf("%v - %v", a0.Tag, a0.Timing))
|
||||
rater.Logger.Debug(fmt.Sprintf("%v - %v", a0.Tag, a0.Timing))
|
||||
go a0.Execute()
|
||||
s.queue = append(s.queue, a0)
|
||||
s.queue = s.queue[1:]
|
||||
sort.Sort(s.queue)
|
||||
} else {
|
||||
d := a0.GetNextStartTime().Sub(now)
|
||||
timespans.Logger.Info(fmt.Sprintf("Timer set to wait for %v", d))
|
||||
rater.Logger.Info(fmt.Sprintf("Timer set to wait for %v", d))
|
||||
s.timer = time.NewTimer(d)
|
||||
select {
|
||||
case <-s.timer.C:
|
||||
// timer has expired
|
||||
timespans.Logger.Info(fmt.Sprintf("Time for action on %v", s.queue[0]))
|
||||
rater.Logger.Info(fmt.Sprintf("Time for action on %v", s.queue[0]))
|
||||
case <-s.restartLoop:
|
||||
// nothing to do, just continue the loop
|
||||
}
|
||||
@@ -63,22 +63,22 @@ func (s *Scheduler) Loop() {
|
||||
}
|
||||
}
|
||||
|
||||
func (s *Scheduler) LoadActionTimings(storage timespans.DataStorage) {
|
||||
func (s *Scheduler) LoadActionTimings(storage rater.DataStorage) {
|
||||
actionTimings, err := storage.GetAllActionTimings()
|
||||
if err != nil {
|
||||
timespans.Logger.Warning(fmt.Sprintf("Cannot get action timings: %v", err))
|
||||
rater.Logger.Warning(fmt.Sprintf("Cannot get action timings: %v", err))
|
||||
}
|
||||
// recreate the queue
|
||||
s.queue = timespans.ActionTimingPriotityList{}
|
||||
s.queue = rater.ActionTimingPriotityList{}
|
||||
for key, ats := range actionTimings {
|
||||
toBeSaved := false
|
||||
isAsap := false
|
||||
newAts := make([]*timespans.ActionTiming, 0)
|
||||
newAts := make([]*rater.ActionTiming, 0)
|
||||
for _, at := range ats {
|
||||
isAsap = at.CheckForASAP()
|
||||
toBeSaved = toBeSaved || isAsap
|
||||
if at.IsOneTimeRun() {
|
||||
timespans.Logger.Info(fmt.Sprintf("Time for one time action on %v", key))
|
||||
rater.Logger.Info(fmt.Sprintf("Time for one time action on %v", key))
|
||||
go at.Execute()
|
||||
// do not append it to the newAts list to be saved
|
||||
} else {
|
||||
|
||||
@@ -20,7 +20,7 @@ package sessionmanager
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/cgrates/cgrates/timespans"
|
||||
"github.com/cgrates/cgrates/rater"
|
||||
"regexp"
|
||||
"strconv"
|
||||
"strings"
|
||||
@@ -82,7 +82,7 @@ func (fsev *FSEvent) New(body string) Event {
|
||||
if len(fields) == 3 {
|
||||
fsev.Fields[fields[1]] = fields[2]
|
||||
} else {
|
||||
timespans.Logger.Err(fmt.Sprintf("malformed event field: %v", fields))
|
||||
rater.Logger.Err(fmt.Sprintf("malformed event field: %v", fields))
|
||||
}
|
||||
}
|
||||
return fsev
|
||||
|
||||
@@ -22,7 +22,7 @@ import (
|
||||
"bufio"
|
||||
"errors"
|
||||
"fmt"
|
||||
"github.com/cgrates/cgrates/timespans"
|
||||
"github.com/cgrates/cgrates/rater"
|
||||
"net"
|
||||
"time"
|
||||
)
|
||||
@@ -34,12 +34,12 @@ type FSSessionManager struct {
|
||||
buf *bufio.Reader
|
||||
sessions []*Session
|
||||
sessionDelegate *SessionDelegate
|
||||
loggerDB timespans.DataStorage
|
||||
loggerDB rater.DataStorage
|
||||
address, pass string
|
||||
delayFunc func() int
|
||||
}
|
||||
|
||||
func NewFSSessionManager(storage timespans.DataStorage) *FSSessionManager {
|
||||
func NewFSSessionManager(storage rater.DataStorage) *FSSessionManager {
|
||||
return &FSSessionManager{loggerDB: storage}
|
||||
}
|
||||
|
||||
@@ -47,7 +47,7 @@ func NewFSSessionManager(storage timespans.DataStorage) *FSSessionManager {
|
||||
// listening for events in json format.
|
||||
func (sm *FSSessionManager) Connect(ed *SessionDelegate, address, pass string) error {
|
||||
if ed == nil {
|
||||
timespans.Logger.Crit("Please provide a non nil SessionDelegate")
|
||||
rater.Logger.Crit("Please provide a non nil SessionDelegate")
|
||||
return errors.New("nil session delegate")
|
||||
}
|
||||
sm.sessionDelegate = ed
|
||||
@@ -59,7 +59,7 @@ func (sm *FSSessionManager) Connect(ed *SessionDelegate, address, pass string) e
|
||||
}
|
||||
conn, err := net.Dial("tcp", address)
|
||||
if err != nil {
|
||||
timespans.Logger.Warning("Could not connect to freeswitch server!")
|
||||
rater.Logger.Warning("Could not connect to freeswitch server!")
|
||||
return err
|
||||
}
|
||||
sm.conn = conn
|
||||
@@ -88,13 +88,13 @@ func (sm *FSSessionManager) Connect(ed *SessionDelegate, address, pass string) e
|
||||
func (sm *FSSessionManager) readNextEvent(exitChan chan bool) (ev Event) {
|
||||
body, err := sm.buf.ReadString('}')
|
||||
if err != nil {
|
||||
timespans.Logger.Warning("Could not read from freeswitch connection!")
|
||||
rater.Logger.Warning("Could not read from freeswitch connection!")
|
||||
// wait until a sec
|
||||
time.Sleep(time.Duration(sm.delayFunc()) * time.Second)
|
||||
// try to reconnect
|
||||
err = sm.Connect(sm.sessionDelegate, sm.address, sm.pass)
|
||||
if err == nil {
|
||||
timespans.Logger.Info("Successfuly reconnected to freeswitch! ")
|
||||
rater.Logger.Info("Successfuly reconnected to freeswitch! ")
|
||||
exitChan <- true
|
||||
}
|
||||
}
|
||||
@@ -142,7 +142,7 @@ func (sm *FSSessionManager) OnHeartBeat(ev Event) {
|
||||
if sm.sessionDelegate != nil {
|
||||
sm.sessionDelegate.OnHeartBeat(ev)
|
||||
} else {
|
||||
timespans.Logger.Info("♥")
|
||||
rater.Logger.Info("♥")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -151,7 +151,7 @@ func (sm *FSSessionManager) OnChannelPark(ev Event) {
|
||||
if sm.sessionDelegate != nil {
|
||||
sm.sessionDelegate.OnChannelPark(ev, sm)
|
||||
} else {
|
||||
timespans.Logger.Info("park")
|
||||
rater.Logger.Info("park")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -164,7 +164,7 @@ func (sm *FSSessionManager) OnChannelAnswer(ev Event) {
|
||||
sm.sessionDelegate.OnChannelAnswer(ev, s)
|
||||
}
|
||||
} else {
|
||||
timespans.Logger.Info("answer")
|
||||
rater.Logger.Info("answer")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -175,7 +175,7 @@ func (sm *FSSessionManager) OnChannelHangupComplete(ev Event) {
|
||||
sm.sessionDelegate.OnChannelHangupComplete(ev, s)
|
||||
s.SaveOperations()
|
||||
} else {
|
||||
timespans.Logger.Info("HangupComplete")
|
||||
rater.Logger.Info("HangupComplete")
|
||||
}
|
||||
if s != nil {
|
||||
|
||||
@@ -193,7 +193,7 @@ func (sm *FSSessionManager) GetSessionDelegate() *SessionDelegate {
|
||||
return sm.sessionDelegate
|
||||
}
|
||||
|
||||
func (sm *FSSessionManager) GetDbLogger() timespans.DataStorage {
|
||||
func (sm *FSSessionManager) GetDbLogger() rater.DataStorage {
|
||||
return sm.loggerDB
|
||||
}
|
||||
|
||||
|
||||
@@ -20,7 +20,7 @@ package sessionmanager
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/cgrates/cgrates/timespans"
|
||||
"github.com/cgrates/cgrates/rater"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
@@ -29,10 +29,10 @@ import (
|
||||
// actions and a channel to signal end of the debit loop.
|
||||
type Session struct {
|
||||
uuid string
|
||||
callDescriptor *timespans.CallDescriptor
|
||||
callDescriptor *rater.CallDescriptor
|
||||
sessionManager SessionManager
|
||||
stopDebit chan bool
|
||||
CallCosts []*timespans.CallCost
|
||||
CallCosts []*rater.CallCost
|
||||
}
|
||||
|
||||
// Creates a new session and starts the debit loop
|
||||
@@ -43,11 +43,11 @@ func NewSession(ev Event, sm SessionManager) (s *Session) {
|
||||
}
|
||||
startTime, err := ev.GetStartTime(START_TIME)
|
||||
if err != nil {
|
||||
timespans.Logger.Err("Error parsing answer event start time, using time.Now!")
|
||||
rater.Logger.Err("Error parsing answer event start time, using time.Now!")
|
||||
startTime = time.Now()
|
||||
}
|
||||
|
||||
cd := ×pans.CallDescriptor{
|
||||
cd := &rater.CallDescriptor{
|
||||
Direction: ev.GetDirection(),
|
||||
Tenant: ev.GetTenant(),
|
||||
TOR: ev.GetTOR(),
|
||||
@@ -96,7 +96,7 @@ func (s *Session) getSessionDurationFrom(now time.Time) (d time.Duration) {
|
||||
seconds := now.Sub(s.callDescriptor.TimeStart).Seconds()
|
||||
d, err := time.ParseDuration(fmt.Sprintf("%ds", int(seconds)))
|
||||
if err != nil {
|
||||
timespans.Logger.Err(fmt.Sprintf("Cannot parse session duration %v", seconds))
|
||||
rater.Logger.Err(fmt.Sprintf("Cannot parse session duration %v", seconds))
|
||||
}
|
||||
return
|
||||
}
|
||||
@@ -136,8 +136,8 @@ func (s *Session) SaveOperations() {
|
||||
firstCC.Merge(cc)
|
||||
}
|
||||
if s.sessionManager.GetDbLogger() != nil {
|
||||
s.sessionManager.GetDbLogger().LogCallCost(s.uuid, timespans.SESSION_MANAGER_SOURCE, firstCC)
|
||||
s.sessionManager.GetDbLogger().LogCallCost(s.uuid, rater.SESSION_MANAGER_SOURCE, firstCC)
|
||||
}
|
||||
timespans.Logger.Debug(firstCC.String())
|
||||
rater.Logger.Debug(firstCC.String())
|
||||
}()
|
||||
}
|
||||
|
||||
@@ -20,26 +20,26 @@ package sessionmanager
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/cgrates/cgrates/timespans"
|
||||
"github.com/cgrates/cgrates/rater"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
// Sample SessionDelegate calling the timespans methods through the RPC interface
|
||||
type SessionDelegate struct {
|
||||
Connector timespans.Connector
|
||||
Connector rater.Connector
|
||||
DebitPeriod time.Duration
|
||||
}
|
||||
|
||||
func (rsd *SessionDelegate) OnHeartBeat(ev Event) {
|
||||
timespans.Logger.Info("freeswitch ♥")
|
||||
rater.Logger.Info("freeswitch ♥")
|
||||
}
|
||||
|
||||
func (rsd *SessionDelegate) OnChannelPark(ev Event, sm SessionManager) {
|
||||
timespans.Logger.Info("freeswitch park")
|
||||
rater.Logger.Info("freeswitch park")
|
||||
startTime, err := ev.GetStartTime(PARK_TIME)
|
||||
if err != nil {
|
||||
timespans.Logger.Err("Error parsing answer event start time, using time.Now!")
|
||||
rater.Logger.Err("Error parsing answer event start time, using time.Now!")
|
||||
startTime = time.Now()
|
||||
}
|
||||
// if there is no account configured leave the call alone
|
||||
@@ -48,10 +48,10 @@ func (rsd *SessionDelegate) OnChannelPark(ev Event, sm SessionManager) {
|
||||
}
|
||||
if ev.MissingParameter() {
|
||||
sm.UnparkCall(ev.GetUUID(), ev.GetCallDestNb(), MISSING_PARAMETER)
|
||||
timespans.Logger.Err(fmt.Sprintf("Missing parameter for %s", ev.GetUUID()))
|
||||
rater.Logger.Err(fmt.Sprintf("Missing parameter for %s", ev.GetUUID()))
|
||||
return
|
||||
}
|
||||
cd := timespans.CallDescriptor{
|
||||
cd := rater.CallDescriptor{
|
||||
Direction: ev.GetDirection(),
|
||||
Tenant: ev.GetTenant(),
|
||||
TOR: ev.GetTOR(),
|
||||
@@ -63,13 +63,13 @@ func (rsd *SessionDelegate) OnChannelPark(ev Event, sm SessionManager) {
|
||||
var remainingSeconds float64
|
||||
err = rsd.Connector.GetMaxSessionTime(cd, &remainingSeconds)
|
||||
if err != nil {
|
||||
timespans.Logger.Err(fmt.Sprintf("Could not get max session time for %s: %v", ev.GetUUID(), err))
|
||||
rater.Logger.Err(fmt.Sprintf("Could not get max session time for %s: %v", ev.GetUUID(), err))
|
||||
sm.UnparkCall(ev.GetUUID(), ev.GetCallDestNb(), SYSTEM_ERROR)
|
||||
return
|
||||
}
|
||||
timespans.Logger.Info(fmt.Sprintf("Remaining seconds: %v", remainingSeconds))
|
||||
rater.Logger.Info(fmt.Sprintf("Remaining seconds: %v", remainingSeconds))
|
||||
if remainingSeconds == 0 {
|
||||
timespans.Logger.Info(fmt.Sprintf("Not enough credit for trasferring the call %s for %s.", ev.GetUUID(), cd.GetKey()))
|
||||
rater.Logger.Info(fmt.Sprintf("Not enough credit for trasferring the call %s for %s.", ev.GetUUID(), cd.GetKey()))
|
||||
sm.UnparkCall(ev.GetUUID(), ev.GetCallDestNb(), INSUFFICIENT_FUNDS)
|
||||
return
|
||||
}
|
||||
@@ -77,22 +77,22 @@ func (rsd *SessionDelegate) OnChannelPark(ev Event, sm SessionManager) {
|
||||
}
|
||||
|
||||
func (rsd *SessionDelegate) OnChannelAnswer(ev Event, s *Session) {
|
||||
timespans.Logger.Info("freeswitch answer")
|
||||
rater.Logger.Info("freeswitch answer")
|
||||
}
|
||||
|
||||
func (rsd *SessionDelegate) OnChannelHangupComplete(ev Event, s *Session) {
|
||||
if ev.GetReqType() == REQTYPE_POSTPAID {
|
||||
startTime, err := ev.GetStartTime(START_TIME)
|
||||
if err != nil {
|
||||
timespans.Logger.Crit("Error parsing postpaid call start time from event")
|
||||
rater.Logger.Crit("Error parsing postpaid call start time from event")
|
||||
return
|
||||
}
|
||||
endTime, err := ev.GetEndTime()
|
||||
if err != nil {
|
||||
timespans.Logger.Crit("Error parsing postpaid call start time from event")
|
||||
rater.Logger.Crit("Error parsing postpaid call start time from event")
|
||||
return
|
||||
}
|
||||
cd := timespans.CallDescriptor{
|
||||
cd := rater.CallDescriptor{
|
||||
Direction: ev.GetDirection(),
|
||||
Tenant: ev.GetTenant(),
|
||||
TOR: ev.GetTOR(),
|
||||
@@ -102,10 +102,10 @@ func (rsd *SessionDelegate) OnChannelHangupComplete(ev Event, s *Session) {
|
||||
TimeStart: startTime,
|
||||
TimeEnd: endTime,
|
||||
}
|
||||
cc := ×pans.CallCost{}
|
||||
cc := &rater.CallCost{}
|
||||
err = rsd.Connector.Debit(cd, cc)
|
||||
if err != nil {
|
||||
timespans.Logger.Err(fmt.Sprintf("Error making the general debit for postpaid call: %v", ev.GetUUID()))
|
||||
rater.Logger.Err(fmt.Sprintf("Error making the general debit for postpaid call: %v", ev.GetUUID()))
|
||||
return
|
||||
}
|
||||
s.CallCosts = append(s.CallCosts, cc)
|
||||
@@ -122,7 +122,7 @@ func (rsd *SessionDelegate) OnChannelHangupComplete(ev Event, s *Session) {
|
||||
refoundDuration := end.Sub(start).Seconds()
|
||||
cost := 0.0
|
||||
seconds := 0.0
|
||||
timespans.Logger.Info(fmt.Sprintf("Refund duration: %v", refoundDuration))
|
||||
rater.Logger.Info(fmt.Sprintf("Refund duration: %v", refoundDuration))
|
||||
for i := len(lastCC.Timespans) - 1; i >= 0; i-- {
|
||||
ts := lastCC.Timespans[i]
|
||||
tsDuration := ts.GetDuration().Seconds()
|
||||
@@ -151,7 +151,7 @@ func (rsd *SessionDelegate) OnChannelHangupComplete(ev Event, s *Session) {
|
||||
}
|
||||
}
|
||||
if cost > 0 {
|
||||
cd := ×pans.CallDescriptor{
|
||||
cd := &rater.CallDescriptor{
|
||||
Direction: lastCC.Direction,
|
||||
Tenant: lastCC.Tenant,
|
||||
TOR: lastCC.TOR,
|
||||
@@ -163,11 +163,11 @@ func (rsd *SessionDelegate) OnChannelHangupComplete(ev Event, s *Session) {
|
||||
var response float64
|
||||
err := rsd.Connector.DebitCents(*cd, &response)
|
||||
if err != nil {
|
||||
timespans.Logger.Err(fmt.Sprintf("Debit cents failed: %v", err))
|
||||
rater.Logger.Err(fmt.Sprintf("Debit cents failed: %v", err))
|
||||
}
|
||||
}
|
||||
if seconds > 0 {
|
||||
cd := ×pans.CallDescriptor{
|
||||
cd := &rater.CallDescriptor{
|
||||
Direction: lastCC.Direction,
|
||||
TOR: lastCC.TOR,
|
||||
Tenant: lastCC.Tenant,
|
||||
@@ -179,30 +179,30 @@ func (rsd *SessionDelegate) OnChannelHangupComplete(ev Event, s *Session) {
|
||||
var response float64
|
||||
err := rsd.Connector.DebitSeconds(*cd, &response)
|
||||
if err != nil {
|
||||
timespans.Logger.Err(fmt.Sprintf("Debit seconds failed: %v", err))
|
||||
rater.Logger.Err(fmt.Sprintf("Debit seconds failed: %v", err))
|
||||
}
|
||||
}
|
||||
lastCC.Cost -= cost
|
||||
timespans.Logger.Info(fmt.Sprintf("Rambursed %v cents, %v seconds", cost, seconds))
|
||||
rater.Logger.Info(fmt.Sprintf("Rambursed %v cents, %v seconds", cost, seconds))
|
||||
}
|
||||
|
||||
func (rsd *SessionDelegate) LoopAction(s *Session, cd *timespans.CallDescriptor) {
|
||||
cc := ×pans.CallCost{}
|
||||
func (rsd *SessionDelegate) LoopAction(s *Session, cd *rater.CallDescriptor) {
|
||||
cc := &rater.CallCost{}
|
||||
cd.Amount = rsd.DebitPeriod.Seconds()
|
||||
err := rsd.Connector.MaxDebit(*cd, cc)
|
||||
if err != nil {
|
||||
timespans.Logger.Err(fmt.Sprintf("Could not complete debit opperation: %v", err))
|
||||
rater.Logger.Err(fmt.Sprintf("Could not complete debit opperation: %v", err))
|
||||
// disconnect session
|
||||
s.sessionManager.DisconnectSession(s, SYSTEM_ERROR)
|
||||
}
|
||||
nbts := len(cc.Timespans)
|
||||
remainingSeconds := 0.0
|
||||
timespans.Logger.Debug(fmt.Sprintf("Result of MaxDebit call: %v", cc))
|
||||
rater.Logger.Debug(fmt.Sprintf("Result of MaxDebit call: %v", cc))
|
||||
if nbts > 0 {
|
||||
remainingSeconds = cc.Timespans[nbts-1].TimeEnd.Sub(cc.Timespans[0].TimeStart).Seconds()
|
||||
}
|
||||
if remainingSeconds == 0 || err != nil {
|
||||
timespans.Logger.Info(fmt.Sprintf("No credit left: Disconnect %v", s))
|
||||
rater.Logger.Info(fmt.Sprintf("No credit left: Disconnect %v", s))
|
||||
s.Disconnect()
|
||||
return
|
||||
}
|
||||
|
||||
@@ -19,12 +19,12 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
package sessionmanager
|
||||
|
||||
import (
|
||||
"github.com/cgrates/cgrates/timespans"
|
||||
"github.com/cgrates/cgrates/rater"
|
||||
)
|
||||
|
||||
type SessionManager interface {
|
||||
DisconnectSession(*Session, string)
|
||||
UnparkCall(string, string, string)
|
||||
GetSessionDelegate() *SessionDelegate
|
||||
GetDbLogger() timespans.DataStorage
|
||||
GetDbLogger() rater.DataStorage
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user