Add ThresholdConns in AccountS config

This commit is contained in:
TeoV
2020-12-22 13:49:51 +02:00
committed by Dan Christian Bogos
parent 432e0ff41f
commit 610cf862bd
14 changed files with 158 additions and 2 deletions

View File

@@ -24,6 +24,7 @@ import "github.com/cgrates/cgrates/utils"
type AccountSCfg struct {
Enabled bool
IndexedSelects bool
ThresholdSConns []string
StringIndexedFields *[]string
PrefixIndexedFields *[]string
SuffixIndexedFields *[]string
@@ -40,6 +41,16 @@ func (acS *AccountSCfg) loadFromJSONCfg(jsnCfg *AccountSJsonCfg) (err error) {
if jsnCfg.Indexed_selects != nil {
acS.IndexedSelects = *jsnCfg.Indexed_selects
}
if jsnCfg.Thresholds_conns != nil {
acS.ThresholdSConns = make([]string, len(*jsnCfg.Thresholds_conns))
for idx, conn := range *jsnCfg.Thresholds_conns {
// if we have the connection internal we change the name so we can have internal rpc for each subsystem
acS.ThresholdSConns[idx] = conn
if conn == utils.MetaInternal {
acS.ThresholdSConns[idx] = utils.ConcatenatedKey(utils.MetaInternal, utils.MetaThresholds)
}
}
}
if jsnCfg.String_indexed_fields != nil {
sif := make([]string, len(*jsnCfg.String_indexed_fields))
for i, fID := range *jsnCfg.String_indexed_fields {
@@ -74,6 +85,16 @@ func (acS *AccountSCfg) AsMapInterface() (initialMP map[string]interface{}) {
utils.IndexedSelectsCfg: acS.IndexedSelects,
utils.NestedFieldsCfg: acS.NestedFields,
}
if acS.ThresholdSConns != nil {
thresholdSConns := make([]string, len(acS.ThresholdSConns))
for i, item := range acS.ThresholdSConns {
thresholdSConns[i] = item
if item == utils.ConcatenatedKey(utils.MetaInternal, utils.MetaThresholds) {
thresholdSConns[i] = utils.MetaInternal
}
}
initialMP[utils.ThresholdSConnsCfg] = thresholdSConns
}
if acS.StringIndexedFields != nil {
stringIndexedFields := make([]string, len(*acS.StringIndexedFields))
for i, item := range *acS.StringIndexedFields {
@@ -105,6 +126,12 @@ func (acS AccountSCfg) Clone() (cln *AccountSCfg) {
IndexedSelects: acS.IndexedSelects,
NestedFields: acS.NestedFields,
}
if acS.ThresholdSConns != nil {
cln.ThresholdSConns = make([]string, len(acS.ThresholdSConns))
for i, con := range acS.ThresholdSConns {
cln.ThresholdSConns[i] = con
}
}
if acS.StringIndexedFields != nil {
idx := make([]string, len(*acS.StringIndexedFields))
for i, dx := range *acS.StringIndexedFields {

View File

@@ -1082,6 +1082,7 @@ const CGRATES_CFG_JSON = `
"accounts": { // AccountS config
"enabled": false, // starts service: <true|false>
"indexed_selects": true, // enable profile matching exclusively on indexes
"thresholds_conns": [], // connections to ThresholdS for account/balance updates, empty to disable thresholds functionality: <""|*internal|$rpc_conns_id>
//"string_indexed_fields": [], // query indexes based on these fields for faster processing
"prefix_indexed_fields": [], // query indexes based on these fields for faster processing
"suffix_indexed_fields": [], // query indexes based on these fields for faster processing

File diff suppressed because one or more lines are too long

View File

@@ -685,6 +685,7 @@ type ActionSJsonCfg struct {
type AccountSJsonCfg struct {
Enabled *bool
Indexed_selects *bool
Thresholds_conns *[]string
String_indexed_fields *[]string
Prefix_indexed_fields *[]string
Suffix_indexed_fields *[]string

View File

@@ -82,6 +82,11 @@
},
"accounts": {
"enabled": true,
},
"cdrs": {
"enabled": true,
"chargers_conns":["*internal"],

View File

@@ -77,6 +77,11 @@
},
"accounts": {
"enabled": true,
},
"cdrs": {
"enabled": true,
"chargers_conns":["*internal"],

View File

@@ -81,6 +81,11 @@
},
"accounts": {
"enabled": true,
},
"cdrs": {
"enabled": true,
"chargers_conns":["*internal"],

View File

@@ -78,6 +78,11 @@
},
"accounts": {
"enabled": true,
},
"cdrs": {
"enabled": true,
"chargers_conns":["*internal"],

View File

@@ -85,6 +85,11 @@
},
"accounts": {
"enabled": true,
},
"cdrs": {
"enabled": true,
"chargers_conns":["*internal"],

View File

@@ -83,6 +83,11 @@
},
"accounts": {
"enabled": true,
},
"cdrs": {
"enabled": true,
"chargers_conns":["*internal"],

View File

@@ -24,4 +24,5 @@ cgrates.org,ATTR_API_REPLICATOR_AUTH,*auth,*string:~*req.ApiKey:repl12345,,,*req
cgrates.org,ATTR_API_CDRSV2,*auth,*string:~*req.ApiKey:cdrsv212345,,,*req.APIMethods,*constant,CDRsV2.ProcessEvent&CDRsV2.StoreSessionCost,false,20
cgrates.org,ATTR_API_RATES_AUTH,*auth,*string:~*req.ApiKey:rPrf12345,,,*req.APIMethods,*constant,RateSv1.Ping&RateSv1.CostForEvent,false,20
cgrates.org,ATTR_API_CORE_AUTH,*auth,*string:~*req.ApiKey:core12345,,,*req.APIMethods,*constant,CoreSv1.Status&CoreSv1.Ping&CoreSv1.Sleep,false,20
cgrates.org,ATTR_API_ACTIONS_AUTH,*auth,*string:~*req.ApiKey:actPrf12345,,,*req.APIMethods,*constant,ActionSv1.Ping,false,20
cgrates.org,ATTR_API_ACTIONS_AUTH,*auth,*string:~*req.ApiKey:actPrf12345,,,*req.APIMethods,*constant,ActionSv1.Ping,false,20
cgrates.org,ATTR_API_ACCOUNTS_AUTH,*auth,*string:~*req.ApiKey:accPrf12345,,,*req.APIMethods,*constant,AccountSv1.Ping,false,20
1 #Tenant ID Contexts FilterIDs ActivationInterval AttributeFilterIDs Path Type Value Blocker Weight
24 cgrates.org ATTR_API_CDRSV2 *auth *string:~*req.ApiKey:cdrsv212345 *req.APIMethods *constant CDRsV2.ProcessEvent&CDRsV2.StoreSessionCost false 20
25 cgrates.org ATTR_API_RATES_AUTH *auth *string:~*req.ApiKey:rPrf12345 *req.APIMethods *constant RateSv1.Ping&RateSv1.CostForEvent false 20
26 cgrates.org ATTR_API_CORE_AUTH *auth *string:~*req.ApiKey:core12345 *req.APIMethods *constant CoreSv1.Status&CoreSv1.Ping&CoreSv1.Sleep false 20
27 cgrates.org ATTR_API_ACTIONS_AUTH *auth *string:~*req.ApiKey:actPrf12345 *req.APIMethods *constant ActionSv1.Ping false 20
28 cgrates.org ATTR_API_ACCOUNTS_AUTH *auth *string:~*req.ApiKey:accPrf12345 *req.APIMethods *constant AccountSv1.Ping false 20

View File

@@ -25,3 +25,4 @@ cgrates.org,ATTR_API_CDRSV2,*auth,*string:~*req.ApiKey:cdrsv212345,,,*req.APIMet
cgrates.org,ATTR_API_RATES_AUTH,*auth,*string:~*req.ApiKey:rPrf12345,,,*req.APIMethods,*constant,RateSv1.Ping,false,20
cgrates.org,ATTR_API_CORE_AUTH,*auth,*string:~*req.ApiKey:core12345,,,*req.APIMethods,*constant,CoreSv1.Status&CoreSv1.Ping&CoreSv1.Sleep,false,20
cgrates.org,ATTR_API_ACTIONS_AUTH,*auth,*string:~*req.ApiKey:actPrf12345,,,*req.APIMethods,*constant,ActionSv1.Ping,false,20
cgrates.org,ATTR_API_ACCOUNTS_AUTH,*auth,*string:~*req.ApiKey:accPrf12345,,,*req.APIMethods,*constant,AccountSv1.Ping,false,20
1 #Tenant ID Contexts FilterIDs ActivationInterval AttributeFilterIDs Path Type Value Blocker Weight
25 cgrates.org ATTR_API_RATES_AUTH *auth *string:~*req.ApiKey:rPrf12345 *req.APIMethods *constant RateSv1.Ping false 20
26 cgrates.org ATTR_API_CORE_AUTH *auth *string:~*req.ApiKey:core12345 *req.APIMethods *constant CoreSv1.Status&CoreSv1.Ping&CoreSv1.Sleep false 20
27 cgrates.org ATTR_API_ACTIONS_AUTH *auth *string:~*req.ApiKey:actPrf12345 *req.APIMethods *constant ActionSv1.Ping false 20
28 cgrates.org ATTR_API_ACCOUNTS_AUTH *auth *string:~*req.ApiKey:accPrf12345 *req.APIMethods *constant AccountSv1.Ping false 20

View File

@@ -17,3 +17,19 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
*/
package dispatchers
import "github.com/cgrates/cgrates/utils"
func (dS *DispatcherService) AccountSv1Ping(args *utils.CGREventWithOpts, rpl *string) (err error) {
if args == nil {
args = new(utils.CGREventWithOpts)
}
args.CGREvent.Tenant = utils.FirstNonEmpty(args.CGREvent.Tenant, dS.cfg.GeneralCfg().DefaultTenant)
if len(dS.cfg.DispatcherSCfg().AttributeSConns) != 0 {
if err = dS.authorize(utils.AccountSv1Ping, args.CGREvent.Tenant,
utils.IfaceAsString(args.Opts[utils.OptsAPIKey]), args.CGREvent.Time); err != nil {
return
}
}
return dS.Dispatch(args, utils.AccountS, utils.AccountSv1Ping, args, rpl)
}

View File

@@ -0,0 +1,79 @@
// +build integration
/*
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 <http://www.gnu.org/licenses/>
*/
package dispatchers
import (
"testing"
"github.com/cgrates/cgrates/utils"
)
var sTestsDspAccPrf = []func(t *testing.T){
testDspAccPrfPing,
}
//Test start here
func TestDspAccountSIT(t *testing.T) {
var config1, config2, config3 string
switch *dbType {
case utils.MetaInternal:
t.SkipNow()
case utils.MetaMySQL:
config1 = "all_mysql"
config2 = "all2_mysql"
config3 = "dispatchers_mysql"
case utils.MetaMongo:
config1 = "all_mongo"
config2 = "all2_mongo"
config3 = "dispatchers_mongo"
case utils.MetaPostgres:
t.SkipNow()
default:
t.Fatal("Unknown Database type")
}
dispDIR := "dispatchers"
if *encoding == utils.MetaGOB {
dispDIR += "_gob"
}
testDsp(t, sTestsDspAccPrf, "TestDspAccionSIT", config1, config2, config3, "tutorial", "oldtutorial", dispDIR)
}
func testDspAccPrfPing(t *testing.T) {
var reply string
if err := allEngine.RPC.Call(utils.AccountSv1Ping, new(utils.CGREventWithOpts), &reply); err != nil {
t.Error(err)
} else if reply != utils.Pong {
t.Errorf("Received: %s", reply)
}
if err := dispEngine.RPC.Call(utils.AccountSv1Ping, &utils.CGREventWithOpts{
CGREvent: &utils.CGREvent{
Tenant: "cgrates.org",
},
Opts: map[string]interface{}{
utils.OptsAPIKey: "accPrf12345",
},
}, &reply); err != nil {
t.Error(err)
} else if reply != utils.Pong {
t.Errorf("Received: %s", reply)
}
}