created multiple configuration files

This commit is contained in:
Radu Ioan Fericean
2012-07-21 17:02:19 +03:00
parent dd8d68ae92
commit 4fbe9f1eef
15 changed files with 473 additions and 62 deletions

View File

@@ -25,12 +25,14 @@ import (
"github.com/cgrates/cgrates/balancer"
"github.com/cgrates/cgrates/timespans"
"net"
"net/http"
"net/rpc"
"net/rpc/jsonrpc"
"runtime"
)
var (
config = flag.String("config", "/home/rif/Documents/prog/go/src/github.com/cgrates/cgrates/conf/rater.config", "Configuration file location.")
config = flag.String("config", "/home/rif/Documents/prog/go/src/github.com/cgrates/cgrates/conf/rater_standalone.config", "Configuration file location.")
redis_server = "127.0.0.1:6379" // redis address host:port
redis_db = 10 // redis database number
@@ -39,11 +41,12 @@ var (
rater_listen = "127.0.0.1:1234" // listening address host:port
rater_json = false // use JSON for RPC encoding
balancer_enabled = false
balancer_standalone = false // run standalone
balancer_listen_rater = "127.0.0.1:2000" // Rater server address
balancer_listen_api = "127.0.0.1:2001" // Json RPC server address
balancer_json = false // use JSON for RPC encoding
balancer_enabled = false
balancer_standalone = false // run standalone
balancer_listen_rater = "127.0.0.1:2000" // Rater server address
balancer_listen_api = "127.0.0.1:2001" // Json RPC server address
balancer_web_status_server = "127.0.0.1:8000" // Web server address
balancer_json = false // use JSON for RPC encoding
scheduler_enabled = false
scheduler_standalone = false // run standalone (no other service)
@@ -72,7 +75,6 @@ var (
)
func readConfig(configFn string) {
flag.Parse()
c, err := conf.ReadConfigFile(configFn)
if err != nil {
timespans.Logger.Err(fmt.Sprintf("Could not open the configuration file: %v", err))
@@ -90,6 +92,7 @@ func readConfig(configFn string) {
balancer_standalone, _ = c.GetBool("balancer", "standalone")
balancer_listen_rater, _ = c.GetString("balancer", "listen_rater")
balancer_listen_api, _ = c.GetString("balancer", "listen_api")
balancer_web_status_server, _ = c.GetString("balancer", "web_status_server")
balancer_json, _ = c.GetBool("balancer", "json")
scheduler_enabled, _ = c.GetBool("scheduler", "enabled")
@@ -164,15 +167,17 @@ func listenToRPCRequests(responder interface{}, rpcAddress string, json bool) {
}
}
/*func listenToHttpRequests() {
func listenToHttpRequests() {
http.HandleFunc("/", statusHandler)
http.HandleFunc("/getmem", memoryHandler)
http.HandleFunc("/raters", ratersHandler)
log.Print("The server is listening on ", *httpApiAddress)
http.ListenAndServe(*httpApiAddress, nil)
timespans.Logger.Info(fmt.Sprintf("The server is listening on %s", balancer_web_status_server))
http.ListenAndServe(balancer_web_status_server, nil)
}
*/
func main() {
flag.Parse()
runtime.GOMAXPROCS(runtime.NumCPU())
readConfig(*config)
resolveStandaloneConfilcts()
getter, err := timespans.NewRedisStorage(redis_server, redis_db)
@@ -183,10 +188,19 @@ func main() {
defer getter.Close()
timespans.SetStorageGetter(getter)
if !rater_standalone {
if !rater_standalone && !balancer_enabled {
go registerToBalancer(rater_balancer_server, rater_listen)
go stopRaterSingnalHandler(rater_balancer_server, rater_listen, getter)
}
go listenToRPCRequests(&Responder{new(DirectResponder)}, rater_listen, false)
if !balancer_enabled {
go listenToRPCRequests(&Responder{new(DirectResponder)}, rater_listen, rater_json)
}
if balancer_enabled {
go stopBalancerSingnalHandler()
go listenToRPCRequests(new(RaterServer), balancer_listen_rater, false)
go listenToRPCRequests(&Responder{new(RpcResponder)}, balancer_listen_api, balancer_json)
go listenToHttpRequests()
}
<-exitChan
}

View File

@@ -37,6 +37,7 @@ func TestConfig(t *testing.T) {
balancer_standalone != true ||
balancer_listen_rater != "test" ||
balancer_listen_api != "test" ||
balancer_web_status_server != "test" ||
balancer_json != true ||
scheduler_enabled != true ||

View File

@@ -32,20 +32,6 @@ import (
type RaterServer struct{}
/*
Listens for SIGTERM, SIGINT, SIGQUIT system signals and shuts down all the registered raters.
*/
func stopSingnalHandler() {
log.Print("Handling stop signals...")
c := make(chan os.Signal)
signal.Notify(c, syscall.SIGTERM, syscall.SIGINT, syscall.SIGQUIT)
sig := <-c
log.Printf("Caught signal %v, sending shutdownto raters\n", sig)
bal.Shutdown()
exitChan <- true
}
/*
RPC method that receives a rater address, connects to it and ads the pair to the rater list for balancing
*/
@@ -77,6 +63,20 @@ func (rs *RaterServer) UnRegisterRater(clientAddress string, replay *int) error
return nil
}
/*
Listens for SIGTERM, SIGINT, SIGQUIT system signals and shuts down all the registered raters.
*/
func stopBalancerSingnalHandler() {
log.Print("Handling stop signals...")
c := make(chan os.Signal)
signal.Notify(c, syscall.SIGTERM, syscall.SIGINT, syscall.SIGQUIT)
sig := <-c
log.Printf("Caught signal %v, sending shutdownto raters\n", sig)
bal.Shutdown()
exitChan <- true
}
/*
Listens for the SIGTERM, SIGINT, SIGQUIT system signals and gracefuly unregister from balancer and closes the storage before exiting.
*/
@@ -99,7 +99,7 @@ func unregisterFromBalancer(server, listen string) {
client, err := rpc.DialHTTP("tcp", server)
if err != nil {
log.Print("Cannot contact the balancer!")
os.Exit(1)
exitChan <- true
}
var reply int
log.Print("Unregistering from balancer ", server)

View File

@@ -64,8 +64,8 @@ func (r *RpcResponder) GetMaxSessionTime(arg timespans.CallDescriptor, replay *f
return
}
func (r *RpcResponder) AddVolumeDiscountSeconds(arg timespans.CallDescriptor, replay *float64) (err error) {
*replay, err = CallMethod(&arg, "Responder.AddVolumeDiscountSeconds")
func (r *RpcResponder) AddRecievedCallSeconds(arg timespans.CallDescriptor, replay *float64) (err error) {
*replay, err = CallMethod(&arg, "Responder.AddRecievedCallSeconds")
return
}

33
conf/balancer.config Normal file
View File

@@ -0,0 +1,33 @@
# Rating system designed to be used in VoIP Carriers World
# Copyright (C) 2012 Radu Ioan Fericean
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# 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/>
[global]
redis_server = 127.0.0.1:6379 #redis address host:port
redis_db = 10 # redis database number
[rater]
standalone = true # start standalone server (no balancer)
balancer_server = 127.0.0.1:2000 # balancer address host:port
listen_api = 127.0.0.1:1234 # listening address host:port
json = false # use JSON for RPC encoding
[balancer]
enabled = false
standalone = false # run standalone
listen_rater = 127.0.0.1:2000 # Rater server address
listen_api = 127.0.0.1:2001 # Json RPC server address
web_status_server = 127.0.0.1:8000 # Web server address (for status)
json = false # use JSON for RPC encoding

View File

@@ -0,0 +1,27 @@
# Rating system designed to be used in VoIP Carriers World
# Copyright (C) 2012 Radu Ioan Fericean
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# 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/>
[global]
redis_server = 127.0.0.1:6379 #redis address host:port
redis_db = 10 # redis database number
[balancer]
enabled = true
standalone = true # run standalone
listen_rater = 127.0.0.1:2000 # Rater server address
listen_api = 127.0.0.1:2001 # Json RPC server address
web_status_server = 127.0.0.1:8000 # Web server address (for status)
json = false # use JSON for RPC encoding

57
conf/mediator.config Normal file
View File

@@ -0,0 +1,57 @@
# Rating system designed to be used in VoIP Carriers World
# Copyright (C) 2012 Radu Ioan Fericean
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# 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/>
[global]
redis_server = 127.0.0.1:6379 #redis address host:port
redis_db = 10 # redis database number
[rater]
standalone = true # start standalone server (no balancer)
balancer_server = 127.0.0.1:2000 # balancer address host:port
listen_api = 127.0.0.1:1234 # listening address host:port
json = false # use JSON for RPC encoding
[balancer]
enabled = false
standalone = false # run standalone
listen_rater = 127.0.0.1:2000 # Rater server address
listen_api = 127.0.0.1:2001 # Json RPC server address
web_status_server = 127.0.0.1:8000 # Web server address (for status)
json = false # use JSON for RPC encoding
[scheduler]
enabled = false
standalone = false # run standalone (no other service)
json = false # use JSON for RPC encoding
[session_manager]
enabled = false
standalone = false # run standalone
api_server = 127.0.0.1:2000 # balancer address host:port
freeswitch_server = localhost:8021 # freeswitch address host:port
freeswitch_pass = ClueCon # freeswitch address host:port
json = false # use JSON for RPC encoding
[mediator]
enabled = false
standalone = false # run standalone
cdr_file = Master.csv # Freeswitch Master CSV CDR file.
result_file = out.csv # Generated file containing CDR and price info.
host = localhost # The host to connect to. Values that start with / are for UNIX domain sockets.
port = 5432 # The port to bind to.
db = cgrates # The name of the database to connect to.
user = # The user to sign in as.
password = # The user's password.

View File

@@ -0,0 +1,57 @@
# Rating system designed to be used in VoIP Carriers World
# Copyright (C) 2012 Radu Ioan Fericean
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# 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/>
[global]
redis_server = 127.0.0.1:6379 #redis address host:port
redis_db = 10 # redis database number
[rater]
standalone = true # start standalone server (no balancer)
balancer_server = 127.0.0.1:2000 # balancer address host:port
listen_api = 127.0.0.1:1234 # listening address host:port
json = false # use JSON for RPC encoding
[balancer]
enabled = false
standalone = false # run standalone
listen_rater = 127.0.0.1:2000 # Rater server address
listen_api = 127.0.0.1:2001 # Json RPC server address
web_status_server = 127.0.0.1:8000 # Web server address (for status)
json = false # use JSON for RPC encoding
[scheduler]
enabled = false
standalone = false # run standalone (no other service)
json = false # use JSON for RPC encoding
[session_manager]
enabled = false
standalone = false # run standalone
api_server = 127.0.0.1:2000 # balancer address host:port
freeswitch_server = localhost:8021 # freeswitch address host:port
freeswitch_pass = ClueCon # freeswitch address host:port
json = false # use JSON for RPC encoding
[mediator]
enabled = false
standalone = false # run standalone
cdr_file = Master.csv # Freeswitch Master CSV CDR file.
result_file = out.csv # Generated file containing CDR and price info.
host = localhost # The host to connect to. Values that start with / are for UNIX domain sockets.
port = 5432 # The port to bind to.
db = cgrates # The name of the database to connect to.
user = # The user to sign in as.
password = # The user's password.

View File

@@ -19,38 +19,7 @@ redis_server = 127.0.0.1:6379 #redis address host:port
redis_db = 10 # redis database number
[rater]
standalone = true # start standalone server (no balancer)
standalone = false # start standalone server (no balancer)
balancer_server = 127.0.0.1:2000 # balancer address host:port
listen_api = 127.0.0.1:1234 # listening address host:port
json = false # use JSON for RPC encoding
[balancer]
enabled = false
standalone = false # run standalone
listen_rater = 127.0.0.1:2000 # Rater server address
listen_api = 127.0.0.1:2001 # Json RPC server address
json = false # use JSON for RPC encoding
[scheduler]
enabled = false
standalone = false # run standalone (no other service)
json = false # use JSON for RPC encoding
[session_manager]
enabled = false
standalone = false # run standalone
api_server = 127.0.0.1:2000 # balancer address host:port
freeswitch_server = localhost:8021 # freeswitch address host:port
freeswitch_pass = ClueCon # freeswitch address host:port
json = false # use JSON for RPC encoding
[mediator]
enabled = false
standalone = false # run standalone
cdr_file = Master.csv # Freeswitch Master CSV CDR file.
result_file = out.csv # Generated file containing CDR and price info.
host = localhost # The host to connect to. Values that start with / are for UNIX domain sockets.
port = 5432 # The port to bind to.
db = cgrates # The name of the database to connect to.
user = # The user to sign in as.
password = # The user's password.

View File

@@ -0,0 +1,24 @@
# Rating system designed to be used in VoIP Carriers World
# Copyright (C) 2012 Radu Ioan Fericean
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# 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/>
[global]
redis_server = 127.0.0.1:6379 #redis address host:port
redis_db = 10 # redis database number
[rater]
standalone = true # start standalone server (no balancer)
listen_api = 127.0.0.1:1234 # listening address host:port
json = false # use JSON for RPC encoding

57
conf/scheduler.config Normal file
View File

@@ -0,0 +1,57 @@
# Rating system designed to be used in VoIP Carriers World
# Copyright (C) 2012 Radu Ioan Fericean
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# 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/>
[global]
redis_server = 127.0.0.1:6379 #redis address host:port
redis_db = 10 # redis database number
[rater]
standalone = true # start standalone server (no balancer)
balancer_server = 127.0.0.1:2000 # balancer address host:port
listen_api = 127.0.0.1:1234 # listening address host:port
json = false # use JSON for RPC encoding
[balancer]
enabled = false
standalone = false # run standalone
listen_rater = 127.0.0.1:2000 # Rater server address
listen_api = 127.0.0.1:2001 # Json RPC server address
web_status_server = 127.0.0.1:8000 # Web server address (for status)
json = false # use JSON for RPC encoding
[scheduler]
enabled = false
standalone = false # run standalone (no other service)
json = false # use JSON for RPC encoding
[session_manager]
enabled = false
standalone = false # run standalone
api_server = 127.0.0.1:2000 # balancer address host:port
freeswitch_server = localhost:8021 # freeswitch address host:port
freeswitch_pass = ClueCon # freeswitch address host:port
json = false # use JSON for RPC encoding
[mediator]
enabled = false
standalone = false # run standalone
cdr_file = Master.csv # Freeswitch Master CSV CDR file.
result_file = out.csv # Generated file containing CDR and price info.
host = localhost # The host to connect to. Values that start with / are for UNIX domain sockets.
port = 5432 # The port to bind to.
db = cgrates # The name of the database to connect to.
user = # The user to sign in as.
password = # The user's password.

View File

@@ -0,0 +1,57 @@
# Rating system designed to be used in VoIP Carriers World
# Copyright (C) 2012 Radu Ioan Fericean
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# 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/>
[global]
redis_server = 127.0.0.1:6379 #redis address host:port
redis_db = 10 # redis database number
[rater]
standalone = true # start standalone server (no balancer)
balancer_server = 127.0.0.1:2000 # balancer address host:port
listen_api = 127.0.0.1:1234 # listening address host:port
json = false # use JSON for RPC encoding
[balancer]
enabled = false
standalone = false # run standalone
listen_rater = 127.0.0.1:2000 # Rater server address
listen_api = 127.0.0.1:2001 # Json RPC server address
web_status_server = 127.0.0.1:8000 # Web server address (for status)
json = false # use JSON for RPC encoding
[scheduler]
enabled = false
standalone = false # run standalone (no other service)
json = false # use JSON for RPC encoding
[session_manager]
enabled = false
standalone = false # run standalone
api_server = 127.0.0.1:2000 # balancer address host:port
freeswitch_server = localhost:8021 # freeswitch address host:port
freeswitch_pass = ClueCon # freeswitch address host:port
json = false # use JSON for RPC encoding
[mediator]
enabled = false
standalone = false # run standalone
cdr_file = Master.csv # Freeswitch Master CSV CDR file.
result_file = out.csv # Generated file containing CDR and price info.
host = localhost # The host to connect to. Values that start with / are for UNIX domain sockets.
port = 5432 # The port to bind to.
db = cgrates # The name of the database to connect to.
user = # The user to sign in as.
password = # The user's password.

View File

@@ -0,0 +1,57 @@
# Rating system designed to be used in VoIP Carriers World
# Copyright (C) 2012 Radu Ioan Fericean
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# 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/>
[global]
redis_server = 127.0.0.1:6379 #redis address host:port
redis_db = 10 # redis database number
[rater]
standalone = true # start standalone server (no balancer)
balancer_server = 127.0.0.1:2000 # balancer address host:port
listen_api = 127.0.0.1:1234 # listening address host:port
json = false # use JSON for RPC encoding
[balancer]
enabled = false
standalone = false # run standalone
listen_rater = 127.0.0.1:2000 # Rater server address
listen_api = 127.0.0.1:2001 # Json RPC server address
web_status_server = 127.0.0.1:8000 # Web server address (for status)
json = false # use JSON for RPC encoding
[scheduler]
enabled = false
standalone = false # run standalone (no other service)
json = false # use JSON for RPC encoding
[session_manager]
enabled = false
standalone = false # run standalone
api_server = 127.0.0.1:2000 # balancer address host:port
freeswitch_server = localhost:8021 # freeswitch address host:port
freeswitch_pass = ClueCon # freeswitch address host:port
json = false # use JSON for RPC encoding
[mediator]
enabled = false
standalone = false # run standalone
cdr_file = Master.csv # Freeswitch Master CSV CDR file.
result_file = out.csv # Generated file containing CDR and price info.
host = localhost # The host to connect to. Values that start with / are for UNIX domain sockets.
port = 5432 # The port to bind to.
db = cgrates # The name of the database to connect to.
user = # The user to sign in as.
password = # The user's password.

View File

@@ -0,0 +1,57 @@
# Rating system designed to be used in VoIP Carriers World
# Copyright (C) 2012 Radu Ioan Fericean
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# 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/>
[global]
redis_server = 127.0.0.1:6379 #redis address host:port
redis_db = 10 # redis database number
[rater]
standalone = true # start standalone server (no balancer)
balancer_server = 127.0.0.1:2000 # balancer address host:port
listen_api = 127.0.0.1:1234 # listening address host:port
json = false # use JSON for RPC encoding
[balancer]
enabled = false
standalone = false # run standalone
listen_rater = 127.0.0.1:2000 # Rater server address
listen_api = 127.0.0.1:2001 # Json RPC server address
web_status_server = 127.0.0.1:8000 # Web server address (for status)
json = false # use JSON for RPC encoding
[scheduler]
enabled = false
standalone = false # run standalone (no other service)
json = false # use JSON for RPC encoding
[session_manager]
enabled = false
standalone = false # run standalone
api_server = 127.0.0.1:2000 # balancer address host:port
freeswitch_server = localhost:8021 # freeswitch address host:port
freeswitch_pass = ClueCon # freeswitch address host:port
json = false # use JSON for RPC encoding
[mediator]
enabled = false
standalone = false # run standalone
cdr_file = Master.csv # Freeswitch Master CSV CDR file.
result_file = out.csv # Generated file containing CDR and price info.
host = localhost # The host to connect to. Values that start with / are for UNIX domain sockets.
port = 5432 # The port to bind to.
db = cgrates # The name of the database to connect to.
user = # The user to sign in as.
password = # The user's password.

View File

@@ -29,6 +29,7 @@ enabled = true
standalone = true # run standalone
listen_rater = test # Rater server address
listen_api = test # Json RPC server address
web_status_server = test # Web server address (for status)
json = true # use JSON for RPC encoding
[scheduler]