diff --git a/cmd/cgr-console/cgr-console.go b/cmd/cgr-console/cgr-console.go
index 9023bead6..717ad1fe6 100644
--- a/cmd/cgr-console/cgr-console.go
+++ b/cmd/cgr-console/cgr-console.go
@@ -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
diff --git a/cmd/cgr-loader/cgr-loader.go b/cmd/cgr-loader/cgr-loader.go
index 49408858a..69f98cef3 100644
--- a/cmd/cgr-loader/cgr-loader.go
+++ b/cmd/cgr-loader/cgr-loader.go
@@ -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!")
}
diff --git a/cmd/cgr-rater/cgr-rater.go b/cmd/cgr-rater/cgr-rater.go
index e03a5bf65..30a826a8e 100644
--- a/cmd/cgr-rater/cgr-rater.go
+++ b/cmd/cgr-rater/cgr-rater.go
@@ -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)
}
diff --git a/cmd/cgr-rater/registration.go b/cmd/cgr-rater/registration.go
index e4c4dc80f..493afbc04 100644
--- a/cmd/cgr-rater/registration.go
+++ b/cmd/cgr-rater/registration.go
@@ -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()
diff --git a/cmd/stress/cgr-raterstress/cgr-raterstress.go b/cmd/stress/cgr-raterstress/cgr-raterstress.go
index d862766c8..829810532 100644
--- a/cmd/stress/cgr-raterstress/cgr-raterstress.go
+++ b/cmd/stress/cgr-raterstress/cgr-raterstress.go
@@ -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 {
diff --git a/cmd/stress/cgr-spansstress/cgr-spansstress.go b/cmd/stress/cgr-spansstress/cgr-spansstress.go
index 1bbc6979b..d3a6832e0 100644
--- a/cmd/stress/cgr-spansstress/cgr-spansstress.go
+++ b/cmd/stress/cgr-spansstress/cgr-spansstress.go
@@ -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++ {
diff --git a/mediator/mediator.go b/mediator/mediator.go
index 22d004ff4..53844470f 100644
--- a/mediator/mediator.go
+++ b/mediator/mediator.go
@@ -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
}
diff --git a/timespans/accountlock.go b/rater/accountlock.go
similarity index 98%
rename from timespans/accountlock.go
rename to rater/accountlock.go
index 43aa0a7b9..abd9666e2 100644
--- a/timespans/accountlock.go
+++ b/rater/accountlock.go
@@ -16,7 +16,7 @@ You should have received a copy of the GNU General Public License
along with this program. If not, see
*/
-package timespans
+package rater
import (
"sync"
diff --git a/timespans/accountlock_test.go b/rater/accountlock_test.go
similarity index 98%
rename from timespans/accountlock_test.go
rename to rater/accountlock_test.go
index c54dc00df..ad6c590c2 100644
--- a/timespans/accountlock_test.go
+++ b/rater/accountlock_test.go
@@ -16,7 +16,7 @@ You should have received a copy of the GNU General Public License
along with this program. If not, see
*/
-package timespans
+package rater
import (
"testing"
diff --git a/timespans/action.go b/rater/action.go
similarity index 99%
rename from timespans/action.go
rename to rater/action.go
index 57dd0484a..3b148f977 100644
--- a/timespans/action.go
+++ b/rater/action.go
@@ -16,7 +16,7 @@ You should have received a copy of the GNU General Public License
along with this program. If not, see
*/
-package timespans
+package rater
import (
"fmt"
diff --git a/timespans/action_timing.go b/rater/action_timing.go
similarity index 99%
rename from timespans/action_timing.go
rename to rater/action_timing.go
index 3ba0b8b4c..56c753f21 100644
--- a/timespans/action_timing.go
+++ b/rater/action_timing.go
@@ -16,7 +16,7 @@ You should have received a copy of the GNU General Public License
along with this program. If not, see
*/
-package timespans
+package rater
import (
"crypto/rand"
diff --git a/timespans/action_trigger.go b/rater/action_trigger.go
similarity index 99%
rename from timespans/action_trigger.go
rename to rater/action_trigger.go
index 8dc8cb35f..7e8e1e0eb 100644
--- a/timespans/action_trigger.go
+++ b/rater/action_trigger.go
@@ -16,7 +16,7 @@ You should have received a copy of the GNU General Public License
along with this program. If not, see
*/
-package timespans
+package rater
import (
"fmt"
diff --git a/timespans/actions_test.go b/rater/actions_test.go
similarity index 99%
rename from timespans/actions_test.go
rename to rater/actions_test.go
index 1fb28f9af..b3a000598 100644
--- a/timespans/actions_test.go
+++ b/rater/actions_test.go
@@ -16,7 +16,7 @@ You should have received a copy of the GNU General Public License
along with this program. If not, see
*/
-package timespans
+package rater
import (
"reflect"
diff --git a/timespans/activationperiod.go b/rater/activationperiod.go
similarity index 99%
rename from timespans/activationperiod.go
rename to rater/activationperiod.go
index 5ea84a79b..3c229f2ab 100644
--- a/timespans/activationperiod.go
+++ b/rater/activationperiod.go
@@ -16,7 +16,7 @@ You should have received a copy of the GNU General Public License
along with this program. If not, see
*/
-package timespans
+package rater
import (
"github.com/cgrates/cgrates/cache2go"
diff --git a/timespans/activationperiod_test.go b/rater/activationperiod_test.go
similarity index 99%
rename from timespans/activationperiod_test.go
rename to rater/activationperiod_test.go
index c057b521c..c27b33ea0 100644
--- a/timespans/activationperiod_test.go
+++ b/rater/activationperiod_test.go
@@ -16,7 +16,7 @@ You should have received a copy of the GNU General Public License
along with this program. If not, see
*/
-package timespans
+package rater
import (
"encoding/json"
diff --git a/timespans/callcost.go b/rater/callcost.go
similarity index 99%
rename from timespans/callcost.go
rename to rater/callcost.go
index 0142c7305..635e0e7d1 100644
--- a/timespans/callcost.go
+++ b/rater/callcost.go
@@ -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
*/
-package timespans
+package rater
import (
"fmt"
diff --git a/timespans/callcost_test.go b/rater/callcost_test.go
similarity index 99%
rename from timespans/callcost_test.go
rename to rater/callcost_test.go
index f0690ac15..94bcd2049 100644
--- a/timespans/callcost_test.go
+++ b/rater/callcost_test.go
@@ -16,7 +16,7 @@ You should have received a copy of the GNU General Public License
along with this program. If not, see
*/
-package timespans
+package rater
import (
// "log"
diff --git a/timespans/calldesc.go b/rater/calldesc.go
similarity index 99%
rename from timespans/calldesc.go
rename to rater/calldesc.go
index b1b204459..5a00832ec 100644
--- a/timespans/calldesc.go
+++ b/rater/calldesc.go
@@ -16,7 +16,7 @@ You should have received a copy of the GNU General Public License
along with this program. If not, see
*/
-package timespans
+package rater
import (
"errors"
diff --git a/timespans/calldesc_test.go b/rater/calldesc_test.go
similarity index 99%
rename from timespans/calldesc_test.go
rename to rater/calldesc_test.go
index 6619cc002..b75e04891 100644
--- a/timespans/calldesc_test.go
+++ b/rater/calldesc_test.go
@@ -16,7 +16,7 @@ You should have received a copy of the GNU General Public License
along with this program. If not, see
*/
-package timespans
+package rater
import (
"testing"
diff --git a/timespans/csvreader.go b/rater/csvreader.go
similarity index 99%
rename from timespans/csvreader.go
rename to rater/csvreader.go
index a40e6b7d9..d7e9de18a 100644
--- a/timespans/csvreader.go
+++ b/rater/csvreader.go
@@ -16,7 +16,7 @@ You should have received a copy of the GNU General Public License
along with this program. If not, see
*/
-package timespans
+package rater
import (
"encoding/csv"
diff --git a/timespans/csvreader_helpers.go b/rater/csvreader_helpers.go
similarity index 99%
rename from timespans/csvreader_helpers.go
rename to rater/csvreader_helpers.go
index f97f02db7..38d6856ad 100644
--- a/timespans/csvreader_helpers.go
+++ b/rater/csvreader_helpers.go
@@ -16,7 +16,7 @@ You should have received a copy of the GNU General Public License
along with this program. If not, see
*/
-package timespans
+package rater
import (
"bufio"
diff --git a/timespans/csvreader_test.go b/rater/csvreader_test.go
similarity index 99%
rename from timespans/csvreader_test.go
rename to rater/csvreader_test.go
index b1a5da15a..13717cbd7 100644
--- a/timespans/csvreader_test.go
+++ b/rater/csvreader_test.go
@@ -16,7 +16,7 @@ You should have received a copy of the GNU General Public License
along with this program. If not, see
*/
-package timespans
+package rater
import (
"testing"
diff --git a/timespans/dateseries.go b/rater/dateseries.go
similarity index 99%
rename from timespans/dateseries.go
rename to rater/dateseries.go
index 75e662ee2..78b2c47a5 100644
--- a/timespans/dateseries.go
+++ b/rater/dateseries.go
@@ -16,7 +16,7 @@ You should have received a copy of the GNU General Public License
along with this program. If not, see
*/
-package timespans
+package rater
import (
// "log"
diff --git a/timespans/dateseries_test.go b/rater/dateseries_test.go
similarity index 99%
rename from timespans/dateseries_test.go
rename to rater/dateseries_test.go
index 4d87e4465..531eb5efd 100644
--- a/timespans/dateseries_test.go
+++ b/rater/dateseries_test.go
@@ -16,7 +16,7 @@ You should have received a copy of the GNU General Public License
along with this program. If not, see
*/
-package timespans
+package rater
import (
"encoding/json"
diff --git a/timespans/destinations.go b/rater/destinations.go
similarity index 99%
rename from timespans/destinations.go
rename to rater/destinations.go
index 921121ad8..b84b6de73 100644
--- a/timespans/destinations.go
+++ b/rater/destinations.go
@@ -16,7 +16,7 @@ You should have received a copy of the GNU General Public License
along with this program. If not, see
*/
-package timespans
+package rater
import (
"github.com/cgrates/cgrates/cache2go"
diff --git a/timespans/destinations_test.go b/rater/destinations_test.go
similarity index 99%
rename from timespans/destinations_test.go
rename to rater/destinations_test.go
index 3f87545e1..9cfff7f32 100644
--- a/timespans/destinations_test.go
+++ b/rater/destinations_test.go
@@ -16,7 +16,7 @@ You should have received a copy of the GNU General Public License
along with this program. If not, see
*/
-package timespans
+package rater
import (
"encoding/json"
diff --git a/timespans/interval.go b/rater/interval.go
similarity index 99%
rename from timespans/interval.go
rename to rater/interval.go
index 7595bf2b7..6e1cb6de1 100644
--- a/timespans/interval.go
+++ b/rater/interval.go
@@ -16,7 +16,7 @@ You should have received a copy of the GNU General Public License
along with thresult program. If not, see
*/
-package timespans
+package rater
import (
"fmt"
diff --git a/timespans/interval_test.go b/rater/interval_test.go
similarity index 99%
rename from timespans/interval_test.go
rename to rater/interval_test.go
index 690523386..d70f77f96 100644
--- a/timespans/interval_test.go
+++ b/rater/interval_test.go
@@ -16,7 +16,7 @@ You should have received a copy of the GNU General Public License
along with this program. If not, see
*/
-package timespans
+package rater
import (
"reflect"
diff --git a/timespans/logger.go b/rater/logger.go
similarity index 98%
rename from timespans/logger.go
rename to rater/logger.go
index 09282ea17..66f612153 100644
--- a/timespans/logger.go
+++ b/rater/logger.go
@@ -16,7 +16,7 @@ You should have received a copy of the GNU General Public License
along with this program. If not, see
*/
-package timespans
+package rater
import (
"log"
diff --git a/timespans/minute_buckets.go b/rater/minute_buckets.go
similarity index 99%
rename from timespans/minute_buckets.go
rename to rater/minute_buckets.go
index eeb300d84..b502f6673 100644
--- a/timespans/minute_buckets.go
+++ b/rater/minute_buckets.go
@@ -16,7 +16,7 @@ You should have received a copy of the GNU General Public License
along with this program. If not, see
*/
-package timespans
+package rater
import (
"math"
diff --git a/timespans/minute_buckets_test.go b/rater/minute_buckets_test.go
similarity index 99%
rename from timespans/minute_buckets_test.go
rename to rater/minute_buckets_test.go
index e649ab375..3b6be1fe8 100644
--- a/timespans/minute_buckets_test.go
+++ b/rater/minute_buckets_test.go
@@ -16,7 +16,7 @@ You should have received a copy of the GNU General Public License
along with this program. If not, see
*/
-package timespans
+package rater
import (
"reflect"
diff --git a/timespans/ratingprofile.go b/rater/ratingprofile.go
similarity index 99%
rename from timespans/ratingprofile.go
rename to rater/ratingprofile.go
index 18f729cdf..d32462e15 100644
--- a/timespans/ratingprofile.go
+++ b/rater/ratingprofile.go
@@ -16,7 +16,7 @@ You should have received a copy of the GNU General Public License
along with this program. If not, see
*/
-package timespans
+package rater
import (
"errors"
diff --git a/timespans/ratingprofile_test.go b/rater/ratingprofile_test.go
similarity index 99%
rename from timespans/ratingprofile_test.go
rename to rater/ratingprofile_test.go
index 228173d8a..03775b36e 100644
--- a/timespans/ratingprofile_test.go
+++ b/rater/ratingprofile_test.go
@@ -16,7 +16,7 @@ You should have received a copy of the GNU General Public License
along with this program. If not, see
*/
-package timespans
+package rater
import (
"reflect"
diff --git a/timespans/responder.go b/rater/responder.go
similarity index 99%
rename from timespans/responder.go
rename to rater/responder.go
index 4e6e2742d..3effa1997 100644
--- a/timespans/responder.go
+++ b/rater/responder.go
@@ -16,7 +16,7 @@ You should have received a copy of the GNU General Public License
along with this program. If not, see
*/
-package timespans
+package rater
import (
"errors"
diff --git a/timespans/storage_interface.go b/rater/storage_interface.go
similarity index 99%
rename from timespans/storage_interface.go
rename to rater/storage_interface.go
index c32471e3e..0068bd3f1 100644
--- a/timespans/storage_interface.go
+++ b/rater/storage_interface.go
@@ -16,7 +16,7 @@ You should have received a copy of the GNU General Public License
along with this program. If not, see
*/
-package timespans
+package rater
import (
"bytes"
diff --git a/timespans/storage_map.go b/rater/storage_map.go
similarity index 99%
rename from timespans/storage_map.go
rename to rater/storage_map.go
index 0bc50942b..62cf00a4e 100644
--- a/timespans/storage_map.go
+++ b/rater/storage_map.go
@@ -16,7 +16,7 @@ You should have received a copy of the GNU General Public License
along with this program. If not, see
*/
-package timespans
+package rater
import (
"errors"
diff --git a/timespans/storage_mongo.go b/rater/storage_mongo.go
similarity index 99%
rename from timespans/storage_mongo.go
rename to rater/storage_mongo.go
index df79562b5..a252b7066 100644
--- a/timespans/storage_mongo.go
+++ b/rater/storage_mongo.go
@@ -16,7 +16,7 @@ You should have received a copy of the GNU General Public License
along with this program. If not, see
*/
-package timespans
+package rater
import (
"fmt"
diff --git a/timespans/storage_postgres.go b/rater/storage_postgres.go
similarity index 99%
rename from timespans/storage_postgres.go
rename to rater/storage_postgres.go
index 158340ccf..2f5cef802 100644
--- a/timespans/storage_postgres.go
+++ b/rater/storage_postgres.go
@@ -16,7 +16,7 @@ You should have received a copy of the GNU General Public License
along with this program. If not, see
*/
-package timespans
+package rater
import (
"database/sql"
diff --git a/timespans/storage_redis.go b/rater/storage_redis.go
similarity index 99%
rename from timespans/storage_redis.go
rename to rater/storage_redis.go
index a3da35af5..dd988dc79 100644
--- a/timespans/storage_redis.go
+++ b/rater/storage_redis.go
@@ -16,7 +16,7 @@ You should have received a copy of the GNU General Public License
along with this program. If not, see
*/
-package timespans
+package rater
import (
"fmt"
diff --git a/timespans/timespans.go b/rater/timespans.go
similarity index 99%
rename from timespans/timespans.go
rename to rater/timespans.go
index 1aa34bdfd..130067b08 100644
--- a/timespans/timespans.go
+++ b/rater/timespans.go
@@ -16,7 +16,7 @@ You should have received a copy of the GNU General Public License
along with this program. If not, see
*/
-package timespans
+package rater
import (
"fmt"
diff --git a/timespans/timespans_test.go b/rater/timespans_test.go
similarity index 99%
rename from timespans/timespans_test.go
rename to rater/timespans_test.go
index 40b40f005..73cbcc7d6 100644
--- a/timespans/timespans_test.go
+++ b/rater/timespans_test.go
@@ -16,7 +16,7 @@ You should have received a copy of the GNU General Public License
along with this program. If not, see
*/
-package timespans
+package rater
import (
"testing"
diff --git a/timespans/units_counter.go b/rater/units_counter.go
similarity index 99%
rename from timespans/units_counter.go
rename to rater/units_counter.go
index 7b2e21dfe..1edf4c908 100644
--- a/timespans/units_counter.go
+++ b/rater/units_counter.go
@@ -16,7 +16,7 @@ You should have received a copy of the GNU General Public License
along with this program. If not, see
*/
-package timespans
+package rater
import (
"fmt"
diff --git a/timespans/units_counter_test.go b/rater/units_counter_test.go
similarity index 99%
rename from timespans/units_counter_test.go
rename to rater/units_counter_test.go
index 15161e803..7ab8348d3 100644
--- a/timespans/units_counter_test.go
+++ b/rater/units_counter_test.go
@@ -16,7 +16,7 @@ You should have received a copy of the GNU General Public License
along with this program. If not, see
*/
-package timespans
+package rater
import (
"reflect"
diff --git a/timespans/userbalance.go b/rater/userbalance.go
similarity index 99%
rename from timespans/userbalance.go
rename to rater/userbalance.go
index f5c9b0888..d0cfb533d 100644
--- a/timespans/userbalance.go
+++ b/rater/userbalance.go
@@ -16,7 +16,7 @@ You should have received a copy of the GNU General Public License
along with this program. If not, see
*/
-package timespans
+package rater
import (
"errors"
diff --git a/timespans/userbalance_test.go b/rater/userbalance_test.go
similarity index 99%
rename from timespans/userbalance_test.go
rename to rater/userbalance_test.go
index 3c0c7e50d..92d495456 100644
--- a/timespans/userbalance_test.go
+++ b/rater/userbalance_test.go
@@ -16,7 +16,7 @@ You should have received a copy of the GNU General Public License
along with this program. If not, see
*/
-package timespans
+package rater
import (
"reflect"
diff --git a/scheduler/scheduler.go b/scheduler/scheduler.go
index 614d9896b..ee648ed72 100644
--- a/scheduler/scheduler.go
+++ b/scheduler/scheduler.go
@@ -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 {
diff --git a/sessionmanager/fsevent.go b/sessionmanager/fsevent.go
index 1b7b29e8d..9514e8a98 100644
--- a/sessionmanager/fsevent.go
+++ b/sessionmanager/fsevent.go
@@ -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
diff --git a/sessionmanager/fssessionmanager.go b/sessionmanager/fssessionmanager.go
index ab0c484c1..ffa84a63c 100644
--- a/sessionmanager/fssessionmanager.go
+++ b/sessionmanager/fssessionmanager.go
@@ -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
}
diff --git a/sessionmanager/session.go b/sessionmanager/session.go
index 653f1c8bd..c2e1b6461 100644
--- a/sessionmanager/session.go
+++ b/sessionmanager/session.go
@@ -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())
}()
}
diff --git a/sessionmanager/sessiondelegate.go b/sessionmanager/sessiondelegate.go
index eac9f8a9c..5a733f65f 100644
--- a/sessionmanager/sessiondelegate.go
+++ b/sessionmanager/sessiondelegate.go
@@ -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
}
diff --git a/sessionmanager/sessionmanager.go b/sessionmanager/sessionmanager.go
index b0446355e..8b339388f 100644
--- a/sessionmanager/sessionmanager.go
+++ b/sessionmanager/sessionmanager.go
@@ -19,12 +19,12 @@ along with this program. If not, see
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
}
diff --git a/test.sh b/test.sh
index 2a82e8113..354f6e578 100755
--- a/test.sh
+++ b/test.sh
@@ -1,6 +1,6 @@
#! /usr/bin/env sh
-go test github.com/cgrates/cgrates/timespans
+go test github.com/cgrates/cgrates/rater
ts=$?
go test github.com/cgrates/cgrates/sessionmanager
sm=$?