mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-14 12:49:54 +05:00
Updated cfg for preloading + context in methods
This commit is contained in:
committed by
Dan Christian Bogos
parent
a14fc67099
commit
42ab6d3fb6
@@ -318,7 +318,8 @@ type CGRConfig struct {
|
||||
var posibleLoaderTypes = utils.NewStringSet([]string{utils.MetaAttributes,
|
||||
utils.MetaResources, utils.MetaFilters, utils.MetaStats,
|
||||
utils.MetaRoutes, utils.MetaThresholds, utils.MetaChargers,
|
||||
utils.MetaDispatchers, utils.MetaDispatcherHosts, utils.MetaRateProfiles})
|
||||
utils.MetaDispatchers, utils.MetaDispatcherHosts, utils.MetaRateProfiles,
|
||||
utils.MetaAccounts, utils.MetaActionProfiles})
|
||||
|
||||
var possibleReaderTypes = utils.NewStringSet([]string{utils.MetaFileCSV,
|
||||
utils.MetaKafkajsonMap, utils.MetaFileXML, utils.MetaSQL, utils.MetaFileFWV,
|
||||
|
||||
@@ -25,7 +25,7 @@ import (
|
||||
func init() {
|
||||
c := &CmdGetAccounts{
|
||||
name: "accounts",
|
||||
rpcMethod: utils.APIerSv1GetAccount,
|
||||
rpcMethod: utils.AdminSv1GetAccount,
|
||||
rpcParams: &utils.TenantIDWithAPIOpts{},
|
||||
}
|
||||
commands[c.Name()] = c
|
||||
|
||||
@@ -25,7 +25,7 @@ import (
|
||||
func init() {
|
||||
c := &CmdGetAccountsIDs{
|
||||
name: "accounts_ids",
|
||||
rpcMethod: utils.APIerSv1GetAccountIDs,
|
||||
rpcMethod: utils.AdminSv1GetAccountIDs,
|
||||
rpcParams: &utils.PaginatorWithTenant{},
|
||||
}
|
||||
commands[c.Name()] = c
|
||||
|
||||
@@ -23,7 +23,7 @@ import "github.com/cgrates/cgrates/utils"
|
||||
func init() {
|
||||
c := &CmdRemoveAccounts{
|
||||
name: "accounts_remove",
|
||||
rpcMethod: utils.APIerSv1RemoveAccount,
|
||||
rpcMethod: utils.AdminSv1RemoveAccount,
|
||||
rpcParams: &utils.TenantIDWithAPIOpts{},
|
||||
}
|
||||
commands[c.Name()] = c
|
||||
|
||||
@@ -25,7 +25,7 @@ import (
|
||||
func init() {
|
||||
c := &CmdSetAccount{
|
||||
name: "accounts_set",
|
||||
rpcMethod: utils.APIerSv1SetAccount,
|
||||
rpcMethod: utils.AdminSv1SetAccount,
|
||||
rpcParams: &utils.APIAccountWithOpts{},
|
||||
}
|
||||
commands[c.Name()] = c
|
||||
|
||||
@@ -52,6 +52,77 @@
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
"id": "Accounts_Loader",
|
||||
"enabled": true,
|
||||
"dry_run": false,
|
||||
"tenant": "cgrates.org",
|
||||
"run_delay": "0",
|
||||
"lock_filename": ".cgr2.lock",
|
||||
"caches_conns": ["*internal"],
|
||||
"field_separator": ",",
|
||||
"tp_in_dir": "/tmp/AccountsIn",
|
||||
"tp_out_dir": "/tmp/AccountsOut",
|
||||
"data":[
|
||||
{
|
||||
"type": "*accounts",
|
||||
"file_name": "Accounts.csv",
|
||||
"fields": [
|
||||
{"tag": "TenantID", "path": "Tenant", "type": "*variable", "value": "~*req.0", "mandatory": true},
|
||||
{"tag": "ProfileID", "path": "ID", "type": "*variable", "value": "~*req.1", "mandatory": true},
|
||||
{"tag": "FilterIDs", "path": "FilterIDs", "type": "*variable", "value": "~*req.2"},
|
||||
{"tag": "Weights", "path": "Weights", "type": "*variable", "value": "~*req.3"},
|
||||
{"tag": "Opts", "path": "Opts", "type": "*variable", "value": "~*req.4"},
|
||||
{"tag": "BalanceID", "path": "BalanceID", "type": "*variable", "value": "~*req.5"},
|
||||
{"tag": "BalanceFilterIDs", "path": "BalanceFilterIDs", "type": "*variable", "value": "~*req.6"},
|
||||
{"tag": "BalanceWeights", "path": "BalanceWeights", "type": "*variable", "value": "~*req.7"},
|
||||
{"tag": "BalanceType", "path": "BalanceType", "type": "*variable", "value": "~*req.8"},
|
||||
{"tag": "BalanceUnits", "path": "BalanceUnits", "type": "*variable", "value": "~*req.9"},
|
||||
{"tag": "BalanceUnitFactors", "path": "BalanceUnitFactors", "type": "*variable", "value": "~*req.10"},
|
||||
{"tag": "BalanceOpts", "path": "BalanceOpts", "type": "*variable", "value": "~*req.11"},
|
||||
{"tag": "BalanceCostIncrements", "path": "BalanceCostIncrements", "type": "*variable", "value": "~*req.12"},
|
||||
{"tag": "BalanceAttributeIDs", "path": "BalanceAttributeIDs", "type": "*variable", "value": "~*req.13"},
|
||||
{"tag": "BalanceRateProfileIDs", "path": "BalanceRateProfileIDs", "type": "*variable", "value": "~*req.14"},
|
||||
{"tag": "ThresholdIDs", "path": "ThresholdIDs", "type": "*variable", "value": "~*req.15"},
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
"id": "Actions_Loader",
|
||||
"enabled": true,
|
||||
"dry_run": false,
|
||||
"tenant": "cgrates.org",
|
||||
"run_delay": "0",
|
||||
"lock_filename": ".cgr3.lock",
|
||||
"caches_conns": ["*internal"],
|
||||
"field_separator": ",",
|
||||
"tp_in_dir": "/tmp/ActionsIn",
|
||||
"tp_out_dir": "/tmp/ActionsOut",
|
||||
"data":[
|
||||
{
|
||||
"type": "*action_profiles",
|
||||
"file_name": "ActionProfiles.csv",
|
||||
"fields": [
|
||||
{"tag": "TenantID", "path": "Tenant", "type": "*variable", "value": "~*req.0", "mandatory": true},
|
||||
{"tag": "ProfileID", "path": "ID", "type": "*variable", "value": "~*req.1", "mandatory": true},
|
||||
{"tag": "FilterIDs", "path": "FilterIDs", "type": "*variable", "value": "~*req.2"},
|
||||
{"tag": "Weights", "path": "Weights", "type": "*variable", "value": "~*req.3"},
|
||||
{"tag": "Schedule", "path": "Schedule", "type": "*variable", "value": "~*req.4"},
|
||||
{"tag": "TargetType", "path": "TargetType", "type": "*variable", "value": "~*req.5"},
|
||||
{"tag": "TargetIDs", "path": "TargetIDs", "type": "*variable", "value": "~*req.6"},
|
||||
{"tag": "ActionID", "path": "ActionID", "type": "*variable", "value": "~*req.7"},
|
||||
{"tag": "ActionFilterIDs", "path": "ActionFilterIDs", "type": "*variable", "value": "~*req.8"},
|
||||
{"tag": "ActionBlocker", "path": "ActionBlocker", "type": "*variable", "value": "~*req.9"},
|
||||
{"tag": "ActionTTL", "path": "ActionTTL", "type": "*variable", "value": "~*req.10"},
|
||||
{"tag": "ActionType", "path": "ActionType", "type": "*variable", "value": "~*req.11"},
|
||||
{"tag": "ActionOpts", "path": "ActionOpts", "type": "*variable", "value": "~*req.12"},
|
||||
{"tag": "ActionPath", "path": "ActionPath", "type": "*variable", "value": "~*req.13"},
|
||||
{"tag": "ActionValue", "path": "ActionValue", "type": "*variable", "value": "~*req.14"},
|
||||
],
|
||||
},
|
||||
],
|
||||
}
|
||||
],
|
||||
|
||||
"admins": {
|
||||
|
||||
@@ -96,7 +96,7 @@ func (dDP *dynamicDP) fieldAsInterface(fldPath []string) (val interface{}, err e
|
||||
// fieldNameType (~*accounts), accountID(1001) and queried part (BalanceMap.*monetary[0].Value)
|
||||
|
||||
var account utils.Account
|
||||
if err = connMgr.Call(dDP.ctx, dDP.apiConns, utils.APIerSv1GetAccount,
|
||||
if err = connMgr.Call(dDP.ctx, dDP.apiConns, utils.AdminSv1GetAccount,
|
||||
&utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: dDP.tenant, ID: fldPath[1]}}, &account); err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
@@ -49,7 +49,7 @@ func (ld LoaderData) GetRateIDs() ([]string, error) {
|
||||
|
||||
// UpdateFromCSV will update LoaderData with data received from fileName,
|
||||
// contained in record and processed with cfgTpl
|
||||
func (ld LoaderData) UpdateFromCSV(fileName string, record []string,
|
||||
func (ld LoaderData) UpdateFromCSV(ctx *context.Context, fileName string, record []string,
|
||||
cfgTpl []*config.FCTemplate, tnt config.RSRParsers, filterS *engine.FilterS) (err error) {
|
||||
csvProvider := newCsvProvider(record, fileName)
|
||||
tenant, err := tnt.ParseValue("")
|
||||
@@ -59,7 +59,7 @@ func (ld LoaderData) UpdateFromCSV(fileName string, record []string,
|
||||
for _, cfgFld := range cfgTpl {
|
||||
// Make sure filters are matching
|
||||
if len(cfgFld.Filters) != 0 {
|
||||
if pass, err := filterS.Pass(context.TODO(), tenant,
|
||||
if pass, err := filterS.Pass(ctx, tenant,
|
||||
cfgFld.Filters, csvProvider); err != nil {
|
||||
return err
|
||||
} else if !pass {
|
||||
|
||||
@@ -22,6 +22,8 @@ import (
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
"github.com/cgrates/birpc/context"
|
||||
|
||||
"github.com/cgrates/cgrates/engine"
|
||||
|
||||
"github.com/cgrates/cgrates/config"
|
||||
@@ -75,7 +77,7 @@ func TestDataUpdateFromCSVOneFile(t *testing.T) {
|
||||
{"cgrates.org", "ATTR_1", "", "", "", "Subject", "*any", "1001", "true"},
|
||||
}
|
||||
lData := make(LoaderData)
|
||||
if err := lData.UpdateFromCSV("Attributes.csv", rows[0], attrSFlds,
|
||||
if err := lData.UpdateFromCSV(context.Background(), "Attributes.csv", rows[0], attrSFlds,
|
||||
config.NewRSRParsersMustCompile("cgrates.org", utils.InfieldSep), nil); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
@@ -93,7 +95,7 @@ func TestDataUpdateFromCSVOneFile(t *testing.T) {
|
||||
t.Errorf("expecting: %+v, received: %+v", eLData, lData)
|
||||
}
|
||||
lData = make(LoaderData)
|
||||
if err := lData.UpdateFromCSV("Attributes.csv", rows[1], attrSFlds,
|
||||
if err := lData.UpdateFromCSV(context.Background(), "Attributes.csv", rows[1], attrSFlds,
|
||||
config.NewRSRParsersMustCompile("cgrates.org", utils.InfieldSep), nil); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
@@ -159,7 +161,7 @@ func TestDataUpdateFromCSVOneFile2(t *testing.T) {
|
||||
{"cgrates.org", "ATTR_1", "", "", "", "Subject", "*any", "1001", "true"},
|
||||
}
|
||||
lData := make(LoaderData)
|
||||
if err := lData.UpdateFromCSV("Attributes.csv", rows[0], attrSFlds,
|
||||
if err := lData.UpdateFromCSV(context.Background(), "Attributes.csv", rows[0], attrSFlds,
|
||||
config.NewRSRParsersMustCompile("cgrates.org", utils.InfieldSep), nil); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
@@ -177,7 +179,7 @@ func TestDataUpdateFromCSVOneFile2(t *testing.T) {
|
||||
t.Errorf("expecting: %+v, received: %+v", eLData, lData)
|
||||
}
|
||||
lData = make(LoaderData)
|
||||
if err := lData.UpdateFromCSV("Attributes.csv", rows[1], attrSFlds,
|
||||
if err := lData.UpdateFromCSV(context.Background(), "Attributes.csv", rows[1], attrSFlds,
|
||||
config.NewRSRParsersMustCompile("cgrates.org", utils.InfieldSep), nil); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
@@ -240,7 +242,7 @@ func TestDataUpdateFromCSVMultiFiles(t *testing.T) {
|
||||
}
|
||||
lData := make(LoaderData)
|
||||
for fName, record := range loadRun1 {
|
||||
if err := lData.UpdateFromCSV(fName, record, attrSFlds,
|
||||
if err := lData.UpdateFromCSV(context.Background(), fName, record, attrSFlds,
|
||||
config.NewRSRParsersMustCompile("cgrates.org", utils.InfieldSep), nil); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
@@ -288,7 +290,7 @@ func TestUpdateFromCsvParseValueError(t *testing.T) {
|
||||
}
|
||||
tnt := config.NewRSRParsersMustCompile("asd{*duration_seconds}", utils.InfieldSep)
|
||||
expected := "time: invalid duration \"asd\""
|
||||
if err := ldrData.UpdateFromCSV("File1.csv", nil, nil, tnt, nil); err == nil || err.Error() != expected {
|
||||
if err := ldrData.UpdateFromCSV(context.Background(), "File1.csv", nil, nil, tnt, nil); err == nil || err.Error() != expected {
|
||||
t.Errorf("Expected %+v, received %+v", expected, err)
|
||||
}
|
||||
}
|
||||
@@ -320,7 +322,7 @@ func TestUpdateFromCsvWithFiltersError(t *testing.T) {
|
||||
|
||||
for fName, record := range loadRunStr {
|
||||
expected := "Ignoring record: [\"cgrates.org\" \"TEST_1\"] with error : strconv.Atoi: parsing \"Account\": invalid syntax"
|
||||
if err := lData.UpdateFromCSV(fName, record, attrSFlds,
|
||||
if err := lData.UpdateFromCSV(context.Background(), fName, record, attrSFlds,
|
||||
config.NewRSRParsersMustCompile("cgrates.org", utils.InfieldSep), filterS); err == nil || err.Error() != expected {
|
||||
t.Errorf("Expected %+v, received %+v", expected, err)
|
||||
}
|
||||
@@ -353,7 +355,7 @@ func TestUpdateFromCsvWithFiltersContinue(t *testing.T) {
|
||||
filterS := engine.NewFilterS(dftCfg, nil, dm)
|
||||
|
||||
for fName, record := range loadRunStr {
|
||||
if err := lData.UpdateFromCSV(fName, record, attrSFlds,
|
||||
if err := lData.UpdateFromCSV(context.Background(), fName, record, attrSFlds,
|
||||
config.NewRSRParsersMustCompile("cgrates.org", utils.InfieldSep), filterS); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
@@ -229,7 +229,7 @@ func (ldr *Loader) processContent(ctx *context.Context, loaderType, caching stri
|
||||
continue
|
||||
}
|
||||
|
||||
if err := lData.UpdateFromCSV(fName, record,
|
||||
if err := lData.UpdateFromCSV(ctx, fName, record,
|
||||
ldr.dataTpls[loaderType], ldr.tenant, ldr.filterS); err != nil {
|
||||
utils.Logger.Warning(
|
||||
fmt.Sprintf("<%s> <%s> line: %d, error: %s",
|
||||
@@ -701,7 +701,7 @@ func (ldr *Loader) removeContent(ctx *context.Context, loaderType, caching strin
|
||||
continue
|
||||
}
|
||||
|
||||
if err := lData.UpdateFromCSV(fName, record,
|
||||
if err := lData.UpdateFromCSV(ctx, fName, record,
|
||||
ldr.dataTpls[loaderType], ldr.tenant, ldr.filterS); err != nil {
|
||||
utils.Logger.Warning(
|
||||
fmt.Sprintf("<%s> <%s> line: %d, error: %s",
|
||||
|
||||
Reference in New Issue
Block a user