From b91fc4ca21afbea2eca8d68b29bdcdc7572d263e Mon Sep 17 00:00:00 2001 From: DanB Date: Mon, 10 Feb 2014 14:08:24 +0100 Subject: [PATCH] Adding mediator_rpc --- apier/{v1 => }/accounts.go | 0 apier/{v1 => }/apier.go | 0 apier/{v1 => }/apier_local_test.go | 0 apier/{v1 => }/cdrs.go | 0 apier/{v1 => }/tp.go | 0 apier/{v1 => }/tpaccountactions.go | 0 apier/{v1 => }/tpactions.go | 0 apier/{v1 => }/tpactiontimings.go | 0 apier/{v1 => }/tpactiontriggers.go | 0 apier/{v1 => }/tpdestinationrates.go | 0 apier/{v1 => }/tpdestinations.go | 0 apier/{v1 => }/tprates.go | 0 apier/{v1 => }/tpratingplans.go | 0 apier/{v1 => }/tpratingprofiles.go | 0 apier/{v1 => }/tptimings.go | 0 apier/{v1 => }/tutfscsv_local_test.go | 2 +- cmd/cgr-engine/cgr-engine.go | 6 +- console/add_account.go | 2 +- console/add_balance.go | 2 +- console/add_triggeredaction.go | 2 +- console/execute_action.go | 2 +- console/get_balances.go | 2 +- data/conf/samples/cgrates.cfg | 120 ++++++++++++++++++ local_test.sh | 2 +- .../mediation.go => mediator/mediator_rpc.go | 9 +- 25 files changed, 134 insertions(+), 15 deletions(-) rename apier/{v1 => }/accounts.go (100%) rename apier/{v1 => }/apier.go (100%) rename apier/{v1 => }/apier_local_test.go (100%) rename apier/{v1 => }/cdrs.go (100%) rename apier/{v1 => }/tp.go (100%) rename apier/{v1 => }/tpaccountactions.go (100%) rename apier/{v1 => }/tpactions.go (100%) rename apier/{v1 => }/tpactiontimings.go (100%) rename apier/{v1 => }/tpactiontriggers.go (100%) rename apier/{v1 => }/tpdestinationrates.go (100%) rename apier/{v1 => }/tpdestinations.go (100%) rename apier/{v1 => }/tprates.go (100%) rename apier/{v1 => }/tpratingplans.go (100%) rename apier/{v1 => }/tpratingprofiles.go (100%) rename apier/{v1 => }/tptimings.go (100%) rename apier/{v1 => }/tutfscsv_local_test.go (99%) create mode 100644 data/conf/samples/cgrates.cfg rename apier/v1/mediation.go => mediator/mediator_rpc.go (87%) diff --git a/apier/v1/accounts.go b/apier/accounts.go similarity index 100% rename from apier/v1/accounts.go rename to apier/accounts.go diff --git a/apier/v1/apier.go b/apier/apier.go similarity index 100% rename from apier/v1/apier.go rename to apier/apier.go diff --git a/apier/v1/apier_local_test.go b/apier/apier_local_test.go similarity index 100% rename from apier/v1/apier_local_test.go rename to apier/apier_local_test.go diff --git a/apier/v1/cdrs.go b/apier/cdrs.go similarity index 100% rename from apier/v1/cdrs.go rename to apier/cdrs.go diff --git a/apier/v1/tp.go b/apier/tp.go similarity index 100% rename from apier/v1/tp.go rename to apier/tp.go diff --git a/apier/v1/tpaccountactions.go b/apier/tpaccountactions.go similarity index 100% rename from apier/v1/tpaccountactions.go rename to apier/tpaccountactions.go diff --git a/apier/v1/tpactions.go b/apier/tpactions.go similarity index 100% rename from apier/v1/tpactions.go rename to apier/tpactions.go diff --git a/apier/v1/tpactiontimings.go b/apier/tpactiontimings.go similarity index 100% rename from apier/v1/tpactiontimings.go rename to apier/tpactiontimings.go diff --git a/apier/v1/tpactiontriggers.go b/apier/tpactiontriggers.go similarity index 100% rename from apier/v1/tpactiontriggers.go rename to apier/tpactiontriggers.go diff --git a/apier/v1/tpdestinationrates.go b/apier/tpdestinationrates.go similarity index 100% rename from apier/v1/tpdestinationrates.go rename to apier/tpdestinationrates.go diff --git a/apier/v1/tpdestinations.go b/apier/tpdestinations.go similarity index 100% rename from apier/v1/tpdestinations.go rename to apier/tpdestinations.go diff --git a/apier/v1/tprates.go b/apier/tprates.go similarity index 100% rename from apier/v1/tprates.go rename to apier/tprates.go diff --git a/apier/v1/tpratingplans.go b/apier/tpratingplans.go similarity index 100% rename from apier/v1/tpratingplans.go rename to apier/tpratingplans.go diff --git a/apier/v1/tpratingprofiles.go b/apier/tpratingprofiles.go similarity index 100% rename from apier/v1/tpratingprofiles.go rename to apier/tpratingprofiles.go diff --git a/apier/v1/tptimings.go b/apier/tptimings.go similarity index 100% rename from apier/v1/tptimings.go rename to apier/tptimings.go diff --git a/apier/v1/tutfscsv_local_test.go b/apier/tutfscsv_local_test.go similarity index 99% rename from apier/v1/tutfscsv_local_test.go rename to apier/tutfscsv_local_test.go index ddf976c67..70732219a 100644 --- a/apier/v1/tutfscsv_local_test.go +++ b/apier/tutfscsv_local_test.go @@ -172,7 +172,7 @@ func TestFsCsvCall1(t *testing.T) { // Simple test that command is executed without errors if err := rater.Call("Responder.GetCost", cd, &cc); err != nil { t.Error("Got error on Responder.GetCost: ", err.Error()) - } else if cc.ConnectFee != 0.4 && cc.Cost != 0.2 { + } else if cc.GetConnectFee() != 0.4 && cc.Cost != 0.6 { t.Errorf("Calling Responder.GetCost got callcost: %v", cc) } } diff --git a/cmd/cgr-engine/cgr-engine.go b/cmd/cgr-engine/cgr-engine.go index ed656c23c..dc49a818c 100644 --- a/cmd/cgr-engine/cgr-engine.go +++ b/cmd/cgr-engine/cgr-engine.go @@ -29,7 +29,7 @@ import ( "strconv" "time" - "github.com/cgrates/cgrates/apier/v1" + "github.com/cgrates/cgrates/apier" "github.com/cgrates/cgrates/balancer2go" "github.com/cgrates/cgrates/cdrc" "github.com/cgrates/cgrates/cdrs" @@ -118,7 +118,7 @@ func startMediator(responder *engine.Responder, loggerDb engine.LogStorage, cdrD return } engine.Logger.Info("Registering Mediator RPC service.") - server.RpcRegister(&apier.MediatorV1{Mediator: medi}) + server.RpcRegister(&mediator.MediatorV1{Medi: medi}) close(chanDone) } @@ -134,7 +134,7 @@ func registerApier(waitOnChans []chan struct{}) { case <-chn: } } - } +} func startCdrc(cdrsChan chan struct{}) { if cfg.CdrcCdrs == utils.INTERNAL { diff --git a/console/add_account.go b/console/add_account.go index b38642b65..86c68f069 100644 --- a/console/add_account.go +++ b/console/add_account.go @@ -20,7 +20,7 @@ package console import ( "fmt" - "github.com/cgrates/cgrates/apier/v1" + "github.com/cgrates/cgrates/apier" ) func init() { diff --git a/console/add_balance.go b/console/add_balance.go index 582acc8fe..d025c796c 100644 --- a/console/add_balance.go +++ b/console/add_balance.go @@ -22,7 +22,7 @@ import ( "fmt" "strconv" - "github.com/cgrates/cgrates/apier/v1" + "github.com/cgrates/cgrates/apier" "github.com/cgrates/cgrates/engine" ) diff --git a/console/add_triggeredaction.go b/console/add_triggeredaction.go index 3f9e38d0a..a88a7ec8d 100644 --- a/console/add_triggeredaction.go +++ b/console/add_triggeredaction.go @@ -20,7 +20,7 @@ package console import ( "fmt" - "github.com/cgrates/cgrates/apier/v1" + "github.com/cgrates/cgrates/apier" "strconv" ) diff --git a/console/execute_action.go b/console/execute_action.go index 821e6be83..be7095ef0 100644 --- a/console/execute_action.go +++ b/console/execute_action.go @@ -20,7 +20,7 @@ package console import ( "fmt" - "github.com/cgrates/cgrates/apier/v1" + "github.com/cgrates/cgrates/apier" ) func init() { diff --git a/console/get_balances.go b/console/get_balances.go index 32b9c9871..ce7a2e2d1 100644 --- a/console/get_balances.go +++ b/console/get_balances.go @@ -21,7 +21,7 @@ package console import ( "fmt" - "github.com/cgrates/cgrates/apier/v1" + "github.com/cgrates/cgrates/apier" "github.com/cgrates/cgrates/engine" ) diff --git a/data/conf/samples/cgrates.cfg b/data/conf/samples/cgrates.cfg new file mode 100644 index 000000000..f545ecbc4 --- /dev/null +++ b/data/conf/samples/cgrates.cfg @@ -0,0 +1,120 @@ +# CGRateS Sample Configuration file +# +# This file contains the default configuration hardcoded into CGRateS. +# This is what you get when you load CGRateS with an empty configuration file. +# [global] must exist in all files, rest of the configuration is inter-changeable. + +[global] +# ratingdb_type = redis # Rating subsystem database: . +# ratingdb_host = 127.0.0.1 # Rating subsystem database host address. +# ratingdb_port = 6379 # Rating subsystem port to reach the database. +# ratingdb_name = 10 # Rating subsystem database name to connect to. +# ratingdb_user = # Rating subsystem username to use when connecting to database. +# ratingdb_passwd = # Rating subsystem password to use when connecting to database. +# accountdb_type = redis # Accounting subsystem database: . +# accountdb_host = 127.0.0.1 # Accounting subsystem database host address. +# accountdb_port = 6379 # Accounting subsystem port to reach the database. +# accountdb_name = 11 # Accounting subsystem database name to connect to. +# accountdb_user = # Accounting subsystem username to use when connecting to database. +# accountdb_passwd = # Accounting subsystem password to use when connecting to database. +# stordb_type = mysql # Stor database type to use: +# stordb_host = 127.0.0.1 # The host to connect to. Values that start with / are for UNIX domain sockets. +# stordb_port = 3306 # The port to reach the logdb. +# stordb_name = cgrates # The name of the log database to connect to. +# stordb_user = cgrates # Username to use when connecting to stordb. +# stordb_passwd = CGRateS.org # Password to use when connecting to stordb. +# dbdata_encoding = msgpack # The encoding used to store object data in strings: +# rpc_json_listen = 127.0.0.1:2012 # RPC JSON listening address +# rpc_gob_listen = 127.0.0.1:2013 # RPC GOB listening address +# http_listen = 127.0.0.1:2080 # HTTP listening address +# default_reqtype = rated # Default request type to consider when missing from requests: <""|prepaid|postpaid|pseudoprepaid|rated>. +# default_tor = call # Default Type of Record to consider when missing from requests. +# default_tenant = cgrates.org # Default Tenant to consider when missing from requests. +# default_subject = cgrates # Default rating Subject to consider when missing from requests. +# rounding_method = *middle # Rounding method for floats/costs: <*up|*middle|*down> +# rounding_decimals = 4 # Number of decimals to round float/costs at + +[balancer] +# enabled = false # Start Balancer service: . + +[rater] +# enabled = false # Enable RaterCDRSExportPath service: . +# balancer = # Register to Balancer as worker: <""|internal|127.0.0.1:2013>. + +[scheduler] +# enabled = false # Starts Scheduler service: . + +[cdrs] +# enabled = false # Start the CDR Server service: . +# extra_fields = # Extra fields to store in CDRs +# mediator = # Address where to reach the Mediator. Empty for disabling mediation. <""|internal> + +[cdre] +# cdr_format = csv # Exported CDRs format +# extra_fields = # List of extra fields to be exported out in CDRs +# export_dir = /var/log/cgrates/cdr/cdrexport/csv # Path where the exported CDRs will be placed + +[cdrc] +# enabled = false # Enable CDR client functionality +# cdrs = internal # Address where to reach CDR server. +# cdrs_method = http_cgr # Mechanism to use when posting CDRs on server +# run_delay = 0 # Sleep interval in seconds between consecutive runs, 0 to use automation via inotify +# cdr_type = csv # CDR file format . +# cdr_in_dir = /var/log/cgrates/cdr/cdrc/in # Absolute path towards the directory where the CDRs are stored. +# cdr_out_dir = /var/log/cgrates/cdr/cdrc/out # Absolute path towards the directory where processed CDRs will be moved. +# cdr_source_id = freeswitch_csv # Free form field, tag identifying the source of the CDRs within CGRS database. +# accid_field = 0 # Accounting id field identifier. Use index number in case of .csv cdrs. +# reqtype_field = 1 # Request type field identifier. Use index number in case of .csv cdrs. +# direction_field = 2 # Direction field identifier. Use index numbers in case of .csv cdrs. +# tenant_field = 3 # Tenant field identifier. Use index numbers in case of .csv cdrs. +# tor_field = 4 # Type of Record field identifier. Use index numbers in case of .csv cdrs. +# account_field = 5 # Account field identifier. Use index numbers in case of .csv cdrs. +# subject_field = 6 # Subject field identifier. Use index numbers in case of .csv CDRs. +# destination_field = 7 # Destination field identifier. Use index numbers in case of .csv cdrs. +# answer_time_field = 8 # Answer time field identifier. Use index numbers in case of .csv cdrs. +# duration_field = 9 # Duration field identifier. Use index numbers in case of .csv cdrs. +# extra_fields = # Extra fields identifiers. For .csv, format: :[...,:] + +[mediator] +# enabled = false # Starts Mediator service: . +# rater = internal # Address where to reach the Rater: +# rater_reconnects = 3 # Number of reconnects to rater before giving up. +# run_ids = # Identifiers of each extra mediation to run on CDRs +# reqtype_fields = # Name of request type fields to be used during extra mediation. Use index number in case of .csv cdrs. +# direction_fields = # Name of direction fields to be used during extra mediation. Use index numbers in case of .csv cdrs. +# tenant_fields = # Name of tenant fields to be used during extra mediation. Use index numbers in case of .csv cdrs. +# tor_fields = # Name of tor fields to be used during extra mediation. Use index numbers in case of .csv cdrs. +# account_fields = # Name of account fields to be used during extra mediation. Use index numbers in case of .csv cdrs. +# subject_fields = # Name of fields to be used during extra mediation. Use index numbers in case of .csv cdrs. +# destination_fields = # Name of destination fields to be used during extra mediation. Use index numbers in case of .csv cdrs. +# answer_time_fields = # Name of time_answer fields to be used during extra mediation. Use index numbers in case of .csv cdrs. +# duration_fields = # Name of duration fields to be used during extra mediation. Use index numbers in case of .csv cdrs. + +[session_manager] +# enabled = false # Starts SessionManager service: . +# switch_type = freeswitch # Defines the type of switch behind: . +# rater = internal # Address where to reach the Rater. +# rater_reconnects = 3 # Number of reconnects to rater before giving up. +# debit_interval = 10 # Interval to perform debits on. +# max_call_duration = 3h # Maximum call duration a prepaid call can last + +[freeswitch] +# server = 127.0.0.1:8021 # Adress where to connect to FreeSWITCH socket. +# passwd = ClueCon # FreeSWITCH socket password. +# reconnects = 5 # Number of attempts on connect failure. + +[history_server] +# enabled = false # Starts History service: . +# history_dir = /var/log/cgrates/history # Location on disk where to store history files. +# save_interval = 1s # Interval to save changed cache into .git archive + +[history_agent] +# enabled = false # Starts History as a client: . +# server = internal # Address where to reach the master history server: + +[mailer] +# server = localhost # The server to use when sending emails out +# auth_user = cgrates # Authenticate to email server using this user +# auth_passwd = CGRateS.org # Authenticate to email server with this password +# from_address = cgr-mailer@localhost.localdomain # From address used when sending emails out + diff --git a/local_test.sh b/local_test.sh index 77c35e2a3..183830841 100755 --- a/local_test.sh +++ b/local_test.sh @@ -2,7 +2,7 @@ ./test.sh gen=$? -go test github.com/cgrates/cgrates/apier/v1 -local +go test github.com/cgrates/cgrates/apier -local ap=$? go test github.com/cgrates/cgrates/engine -local en=$? diff --git a/apier/v1/mediation.go b/mediator/mediator_rpc.go similarity index 87% rename from apier/v1/mediation.go rename to mediator/mediator_rpc.go index fbe648c28..b5a52ce66 100644 --- a/apier/v1/mediation.go +++ b/mediator/mediator_rpc.go @@ -16,22 +16,21 @@ You should have received a copy of the GNU General Public License along with this program. If not, see */ -package apier +package mediator import ( "fmt" "time" "github.com/cgrates/cgrates/utils" - "github.com/cgrates/cgrates/mediator" ) type MediatorV1 struct { - Mediator *mediator.Mediator + Medi *Mediator } // Remotely start mediation with specific runid, runs asynchronously, it's status will be displayed in syslog func (self *MediatorV1) RateCdrs(attrs utils.AttrRateCdrs, reply *string) error { - if self.Mediator == nil { + if self.Medi == nil { return fmt.Errorf("%s:%s", utils.ERR_SERVER_ERROR, "MediatorNotRunning") } var tStart, tEnd time.Time @@ -46,7 +45,7 @@ func (self *MediatorV1) RateCdrs(attrs utils.AttrRateCdrs, reply *string) error return err } } - if err := self.Mediator.RateCdrs(tStart, tEnd, attrs.RerateErrors, attrs.RerateRated); err != nil { + if err := self.Medi.RateCdrs(tStart, tEnd, attrs.RerateErrors, attrs.RerateRated); err != nil { return fmt.Errorf("%s:%s", utils.ERR_SERVER_ERROR, err.Error()) } return nil