mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-20 06:38:45 +05:00
attributes: dynamicdp updates tenant in each processrun
This commit is contained in:
committed by
Dan Christian Bogos
parent
5fe503605f
commit
f92023b49b
@@ -57,53 +57,75 @@ func TestDiamBalanceEnquiry(t *testing.T) {
|
||||
var reply string
|
||||
if err := client.Call(context.Background(), utils.APIerSv2SetBalance,
|
||||
utils.AttrSetBalance{
|
||||
Tenant: "cgrates.org",
|
||||
Tenant: "cgrates.com",
|
||||
Account: "1001",
|
||||
Value: 10000,
|
||||
BalanceType: utils.MetaMonetary,
|
||||
Value: 50,
|
||||
BalanceType: utils.MetaData,
|
||||
Balance: map[string]any{
|
||||
utils.ID: "balance_monetary",
|
||||
utils.ID: "balance1",
|
||||
},
|
||||
}, &reply); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := client.Call(context.Background(), utils.APIerSv2SetBalance,
|
||||
utils.AttrSetBalance{
|
||||
Tenant: "cgrates.org",
|
||||
Tenant: "cgrates.com",
|
||||
Account: "1001",
|
||||
Value: 50,
|
||||
BalanceType: utils.MetaSMS,
|
||||
Value: 100,
|
||||
BalanceType: utils.MetaData,
|
||||
Balance: map[string]any{
|
||||
utils.ID: "balance_sms",
|
||||
utils.ID: "balance2",
|
||||
},
|
||||
}, &reply); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
alsPrf := &engine.AttributeProfileWithAPIOpts{
|
||||
AttributeProfile: &engine.AttributeProfile{
|
||||
Tenant: "cgrates.org",
|
||||
ID: "ATTR_BALANCE_ENQUIRY",
|
||||
FilterIDs: []string{"*string:~*req.Category:sms"},
|
||||
Attributes: []*engine.Attribute{
|
||||
{
|
||||
Path: utils.MetaReq + utils.NestingSep + "MonBalance",
|
||||
Type: utils.MetaVariable,
|
||||
Value: config.RSRParsers{
|
||||
&config.RSRParser{
|
||||
Rules: "~*accounts.1001.BalanceMap.*monetary[0].Value",
|
||||
alsPrfs := []*engine.AttributeProfileWithAPIOpts{
|
||||
{
|
||||
AttributeProfile: &engine.AttributeProfile{
|
||||
Tenant: "cgrates.org",
|
||||
ID: "ATTR_BALANCE_ENQUIRY",
|
||||
FilterIDs: []string{"*string:~*req.Category:sms"},
|
||||
Attributes: []*engine.Attribute{
|
||||
{
|
||||
Path: utils.MetaTenant,
|
||||
Type: utils.MetaConstant,
|
||||
Value: config.RSRParsers{
|
||||
&config.RSRParser{
|
||||
Rules: "cgrates.com",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
Weight: 20,
|
||||
},
|
||||
},
|
||||
{
|
||||
AttributeProfile: &engine.AttributeProfile{
|
||||
Tenant: "cgrates.com",
|
||||
ID: "ATTR_GET_BALANCE",
|
||||
FilterIDs: []string{"*string:~*req.Account:1001"},
|
||||
Attributes: []*engine.Attribute{
|
||||
{
|
||||
Path: utils.MetaReq + utils.NestingSep + "MonBalance",
|
||||
Type: utils.MetaVariable,
|
||||
Value: config.RSRParsers{
|
||||
&config.RSRParser{
|
||||
Rules: "~*accounts.1001.BalanceMap.*data.GetTotalValue",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
Weight: 10,
|
||||
},
|
||||
Weight: 10,
|
||||
},
|
||||
}
|
||||
alsPrf.Compile()
|
||||
if err := client.Call(context.Background(), utils.APIerSv1SetAttributeProfile,
|
||||
alsPrf, &reply); err != nil {
|
||||
t.Fatal(err)
|
||||
for _, alsPrf := range alsPrfs {
|
||||
alsPrf.Compile()
|
||||
if err := client.Call(context.Background(), utils.APIerSv1SetAttributeProfile,
|
||||
alsPrf, &reply); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
time.Sleep(300 * time.Millisecond)
|
||||
diamClient, err := NewDiameterClient(cfg.DiameterAgentCfg().Listeners[0].Address, "localhost",
|
||||
cfg.DiameterAgentCfg().OriginRealm, cfg.DiameterAgentCfg().VendorID,
|
||||
@@ -166,7 +188,7 @@ func sendBalanceEnquiryQueryCCR(tb testing.TB, client *DiameterClient, replyTime
|
||||
|
||||
if monetaryVal, err := diamAVPAsString(balanceAVPs[0]); err != nil {
|
||||
tb.Fatalf("failed to read monetary balance: %v", err)
|
||||
} else if monetaryVal != "10000" {
|
||||
} else if monetaryVal != "150" {
|
||||
tb.Fatalf("monetary balance=%s, want 10000", monetaryVal)
|
||||
}
|
||||
|
||||
|
||||
@@ -34,6 +34,12 @@
|
||||
"type": "*constant",
|
||||
"value": "sms"
|
||||
},
|
||||
{
|
||||
"tag":"ProcessRuns",
|
||||
"path":"*opts.*attrProcessRuns",
|
||||
"type":"*constant",
|
||||
"value": "2"
|
||||
},
|
||||
{
|
||||
"tag": "Account",
|
||||
"path": "*cgreq.Account",
|
||||
@@ -57,9 +63,9 @@
|
||||
"type": "*variable",
|
||||
"value": "~*cgrep.Attributes.MonBalance",
|
||||
"mandatory": true
|
||||
},
|
||||
}
|
||||
|
||||
]
|
||||
}]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -323,9 +323,9 @@ func (alS *AttributeService) V1ProcessEvent(ctx *context.Context, args *utils.CG
|
||||
var lastID string
|
||||
matchedIDs := make([]string, 0, processRuns)
|
||||
alteredFields := make(utils.StringSet)
|
||||
dynDP := newDynamicDP(alS.cgrcfg.AttributeSCfg().ResourceSConns,
|
||||
alS.cgrcfg.AttributeSCfg().StatSConns, alS.cgrcfg.AttributeSCfg().ApierSConns, nil, nil, args.Tenant, eNV)
|
||||
for i := 0; i < processRuns; i++ {
|
||||
dynDP := newDynamicDP(alS.cgrcfg.AttributeSCfg().ResourceSConns,
|
||||
alS.cgrcfg.AttributeSCfg().StatSConns, alS.cgrcfg.AttributeSCfg().ApierSConns, nil, nil, tnt, eNV)
|
||||
(eNV[utils.MetaVars].(utils.MapStorage))[utils.MetaProcessRuns] = i + 1
|
||||
var evRply *AttrSProcessEventReply
|
||||
evRply, err = alS.processEvent(tnt, args, eNV, dynDP, lastID, processedPrfNo, profileRuns)
|
||||
|
||||
Reference in New Issue
Block a user