From e2088738dfcf80caf92ab419171539c4bed916e1 Mon Sep 17 00:00:00 2001 From: DanB Date: Wed, 30 Jan 2019 11:19:25 +0100 Subject: [PATCH] New dispatchers configuration and DispatcherProfile --- config/config_defaults.go | 19 ++++++++++++++ dispatchers/dispatchers.go | 10 +++++--- dispatchers/libdispatcher.go | 50 ++++++++++++++++++++++++++++++++++++ 3 files changed, 75 insertions(+), 4 deletions(-) create mode 100644 dispatchers/libdispatcher.go diff --git a/config/config_defaults.go b/config/config_defaults.go index 0e4d607f1..ce8ab9758 100755 --- a/config/config_defaults.go +++ b/config/config_defaults.go @@ -737,6 +737,25 @@ const CGRATES_CFG_JSON = ` }, +"dispatchers":{ + "enabled": false, // starts DispatcherS service: . + "conns": { + "sessions_eu": [ + {"address": "127.0.0.1:2012", "transport": "*json"}, + {"address": "127.0.0.2:2012", "transport": "*json"}, + ], + "sessions_us": [ + {"address": "127.0.0.3:2012", "transport": "*json"}, + {"address": "127.0.0.4:2012", "transport": "*json"}, + ], + "sessions_others": [ + {"address": "127.0.0.5:2012", "transport": "*json"}, + {"address": "127.0.0.6:2012", "transport": "*json"}, + ], + }, +}, + + "analyzers":{ "enabled":false // starts AnalyzerS service: . }, diff --git a/dispatchers/dispatchers.go b/dispatchers/dispatchers.go index ad13d8260..3a902f492 100755 --- a/dispatchers/dispatchers.go +++ b/dispatchers/dispatchers.go @@ -55,7 +55,8 @@ func NewDispatcherService(dm *engine.DataManager, rals, resS, thdS, if chargerS != nil && reflect.ValueOf(chargerS).IsNil() { chargerS = nil } - return &DispatcherService{dm: dm, + return &DispatcherService{ + dm: dm, rals: rals, resS: resS, thdS: thdS, @@ -66,7 +67,8 @@ func NewDispatcherService(dm *engine.DataManager, rals, resS, thdS, chargerS: chargerS}, nil } -// DispatcherService is the service handling dispatcher +// DispatcherService is the service handling dispatching towards internal components +// designed to handle automatic partitioning and failover type DispatcherService struct { dm *engine.DataManager rals rpcclient.RpcClientConnection // RALs connections @@ -75,8 +77,8 @@ type DispatcherService struct { statS rpcclient.RpcClientConnection // StatS connections splS rpcclient.RpcClientConnection // SupplierS connections attrS rpcclient.RpcClientConnection // AttributeS connections - sessionS rpcclient.RpcClientConnection // SessionS server connections - chargerS rpcclient.RpcClientConnection // ChargerS server connections + sessionS rpcclient.RpcClientConnection // SessionS connections + chargerS rpcclient.RpcClientConnection // ChargerS connections } // ListenAndServe will initialize the service diff --git a/dispatchers/libdispatcher.go b/dispatchers/libdispatcher.go new file mode 100644 index 000000000..3918a2682 --- /dev/null +++ b/dispatchers/libdispatcher.go @@ -0,0 +1,50 @@ +/* +Real-time Online/Offline Charging System (OCS) for Telecom & ISP environments +Copyright (C) ITsysCOM GmbH + +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 +*/ + +package dispatchers + +import ( + "sort" + + "github.com/cgrates/cgrates/utils" +) + +// DispatcherProfile is the config for one Dispatcher +type DispatcherProfile struct { + Tenant string + ID string + Subsystems []string + FilterIDs []string + ActivationInterval *utils.ActivationInterval // Activation interval + Strategy string + StrategyParams map[string]interface{} // ie for distribution, set here the pool weights + ConnIDs []string // dispatch to these connections + Weight float64 +} + +func (dP *DispatcherProfile) TenantID() string { + return utils.ConcatenatedKey(dP.Tenant, dP.ID) +} + +// DispatcherProfiles is a sortable list of Dispatcher profiles +type DispatcherProfiles []*DispatcherProfile + +// Sort is part of sort interface, sort based on Weight +func (dps DispatcherProfiles) Sort() { + sort.Slice(dps, func(i, j int) bool { return dps[i].Weight > dps[j].Weight }) +}