diff --git a/cmd/cgr-rater/cgr-rater.go b/cmd/cgr-rater/cgr-rater.go index 20c601931..69466adf3 100644 --- a/cmd/cgr-rater/cgr-rater.go +++ b/cmd/cgr-rater/cgr-rater.go @@ -84,12 +84,13 @@ var ( sm_debit_period = 10 // the period to be debited in advanced during a call (in seconds) sm_rpc_encoding = GOB // use JSON for RPC encoding - mediator_enabled = false - mediator_cdr_path = "" // Freeswitch Master CSV CDR path. - mediator_cdr_out_path = "" // Freeswitch Master CSV CDR output path. - mediator_rater = INTERNAL // address where to access rater. Can be internal, direct rater address or the address of a balancer - mediator_rpc_encoding = GOB // use JSON for RPC encoding - mediator_skipdb = false + mediator_enabled = false + mediator_cdr_path = "" // Freeswitch Master CSV CDR path. + mediator_cdr_out_path = "" // Freeswitch Master CSV CDR output path. + mediator_rater = INTERNAL // address where to access rater. Can be internal, direct rater address or the address of a balancer + mediator_rpc_encoding = GOB // use JSON for RPC encoding + mediator_skipdb = false + mediator_pseudo_prepaid = false freeswitch_server = "localhost:8021" // freeswitch address host:port freeswitch_pass = "ClueCon" // reeswitch address host:port @@ -147,6 +148,7 @@ func readConfig(c *conf.ConfigFile) { mediator_rater, _ = c.GetString("mediator", "rater") mediator_rpc_encoding, _ = c.GetString("mediator", "rpc_encoding") mediator_skipdb, _ = c.GetBool("mediator", "skipdb") + mediator_pseudo_prepaid, _ = c.GetBool("mediator", "pseudo_prepaid") freeswitch_server, _ = c.GetString("freeswitch", "server") freeswitch_pass, _ = c.GetString("freeswitch", "pass") @@ -222,7 +224,9 @@ func startMediator(responder *timespans.Responder, loggerDb timespans.DataStorag exitChan <- true } - m, err := mediator.NewMediator(connector, loggerDb, mediator_skipdb, mediator_cdr_out_path, freeswitch_direction, freeswitch_tor, freeswitch_tenant, freeswitch_subject, freeswitch_account, freeswitch_destination, freeswitch_time_start, freeswitch_duration, freeswitch_uuid) + m, err := mediator.NewMediator(connector, loggerDb, mediator_skipdb, mediator_cdr_out_path, mediator_pseudo_prepaid, freeswitch_direction, + 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)) exitChan <- true diff --git a/cmd/cgr-rater/rater_test.go b/cmd/cgr-rater/rater_test.go index 76056d1fe..7379558ab 100644 --- a/cmd/cgr-rater/rater_test.go +++ b/cmd/cgr-rater/rater_test.go @@ -58,6 +58,7 @@ cdr_out_path = test rater = test #address where to access rater. Can be internal, direct rater address or the address of a balancer rpc_encoding = test # use JSON for RPC encoding skipdb = true +pseudo_prepaid = true [scheduler] enabled = true @@ -127,6 +128,7 @@ func TestConfig(t *testing.T) { mediator_rater != "test" || mediator_rpc_encoding != "test" || mediator_skipdb != true || + mediator_pseudo_prepaid != true || freeswitch_server != "test" || freeswitch_pass != "test" || @@ -168,6 +170,8 @@ func TestConfig(t *testing.T) { t.Log(mediator_cdr_path) t.Log(mediator_cdr_out_path) t.Log(mediator_rater) + t.Log(mediator_skipdb) + t.Log(mediator_pseudo_prepaid) t.Log(freeswitch_server) t.Log(freeswitch_pass) t.Log(freeswitch_direction) diff --git a/conf/mediator.config b/conf/mediator.config index 5ace87111..c6e12456b 100644 --- a/conf/mediator.config +++ b/conf/mediator.config @@ -29,6 +29,7 @@ cdr_out_path = /tmp/cgrates/out # Freeswitch Master CSV CDR file. rater = internal #address where to access rater. Can be internal, direct rater address or the address of a balancer rpc_encoding = gob # use JSON for RPC encoding skipdb = false +pseudo_prepaid = false [freeswitch] direction_index = 0 diff --git a/docs/tutorial.rst b/docs/tutorial.rst index ef2de0885..e403565ca 100644 --- a/docs/tutorial.rst +++ b/docs/tutorial.rst @@ -77,6 +77,7 @@ Bellow there is a full configuration file: rater = internal # Address where to access rater. Can be internal, direct rater address or the address of a balancer rpc_encoding = gob # Use json or gob for RPC encoding skipdb = true # Do not look in the database for logged cdrs, ask rater directly + pseudo_prepaid = false # debit the call cost from user balance when getting the cost [scheduler] enabled = true # Start the schedule service diff --git a/mediator/mediator.go b/mediator/mediator.go index 495dc2747..54f1fd9d8 100644 --- a/mediator/mediator.go +++ b/mediator/mediator.go @@ -51,10 +51,11 @@ func (mfi *mediatorFieldIdxs) Load(idxs string) error { } type Mediator struct { - connector timespans.Connector - loggerDb timespans.DataStorage - skipDb bool - outputDir string + connector timespans.Connector + loggerDb timespans.DataStorage + skipDb bool + outputDir string + pseudoPrepaid bool directionIndexs, torIndexs, tenantIndexs, @@ -71,13 +72,15 @@ func NewMediator(connector timespans.Connector, loggerDb timespans.DataStorage, skipDb bool, outputDir string, + pseudoPrepaid bool, directionIndexs, torIndexs, tenantIndexs, subjectIndexs, accountIndexs, destinationIndexs, timeStartIndexs, durationIndexs, uuidIndexs string) (m *Mediator, err error) { m = &Mediator{ - connector: connector, - loggerDb: loggerDb, - skipDb: skipDb, - outputDir: outputDir, + connector: connector, + loggerDb: loggerDb, + skipDb: skipDb, + outputDir: outputDir, + pseudoPrepaid: pseudoPrepaid, } idxs := []string{directionIndexs, torIndexs, tenantIndexs, subjectIndexs, accountIndexs, destinationIndexs, timeStartIndexs, durationIndexs, uuidIndexs} @@ -177,7 +180,6 @@ func (m *Mediator) parseCSV(cdrfn string) (err error) { record = append(record, cost) } w.WriteString(strings.Join(record, ",") + "\n") - } w.Flush() return @@ -214,7 +216,11 @@ func (m *Mediator) getCostsFromRater(record []string, runIdx int) (cc *timespans Destination: record[m.destinationIndexs[runIdx]], TimeStart: t1, TimeEnd: t1.Add(d)} - err = m.connector.GetCost(cd, cc) + if m.pseudoPrepaid { + err = m.connector.Debit(cd, cc) + } else { + err = m.connector.GetCost(cd, cc) + } if err != nil { m.loggerDb.LogError(record[m.uuidIndexs[runIdx]], timespans.MEDIATOR_SOURCE, err.Error()) } else {