mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-11 18:16:24 +05:00
TOR -> Category in relation with DerivedCharging
This commit is contained in:
@@ -38,17 +38,35 @@ func (self *ApierV1) DerivedChargers(attrs utils.AttrDerivedChargers, reply *uti
|
||||
}
|
||||
|
||||
type AttrSetDerivedChargers struct {
|
||||
Tenant, Tor, Direction, Account, Subject string
|
||||
DerivedChargers utils.DerivedChargers
|
||||
Direction, Tenant, Category, Account, Subject string
|
||||
DerivedChargers utils.DerivedChargers
|
||||
}
|
||||
|
||||
func (self *ApierV1) SetDerivedChargers(attrs AttrSetDerivedChargers, reply *utils.DerivedChargers) (err error) {
|
||||
if missing := utils.MissingStructFields(&attrs, []string{"Tenant", "Direction", "Account", "Subject", "DerivedChargers"}); len(missing) != 0 {
|
||||
if missing := utils.MissingStructFields(&attrs, []string{"Tenant", "Category", "Direction", "Account", "Subject", "DerivedChargers"}); len(missing) != 0 {
|
||||
return fmt.Errorf("%s:%v", utils.ERR_MANDATORY_IE_MISSING, missing)
|
||||
}
|
||||
if err := self.AccountDb.SetDerivedChargers(utils.DerivedChargersKey(attrs.Tenant, attrs.Tor, attrs.Direction, attrs.Account, attrs.Subject),
|
||||
if err := self.AccountDb.SetDerivedChargers(utils.DerivedChargersKey(attrs.Direction, attrs.Tenant, attrs.Category, attrs.Account, attrs.Subject),
|
||||
attrs.DerivedChargers); err != nil {
|
||||
return fmt.Errorf("%s:%s", utils.ERR_SERVER_ERROR, err.Error())
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
/*
|
||||
type AttrRemDerivedChargers struct {
|
||||
Tenant, Category, Direction, Account, Subject string
|
||||
}
|
||||
|
||||
func (self *ApierV1) RemDerivedChargers(attrs AttrRemDerivedChargers, reply *string) error {
|
||||
if missing := utils.MissingStructFields(&attrs, ]string{"Tenant", "Category", "Direction", "Account", "Subject"}); len(missing) != 0 { //Params missing
|
||||
return fmt.Errorf("%s:%v", utils.ERR_MANDATORY_IE_MISSING, missing)
|
||||
}
|
||||
if err := self.StorDb.RemTPData(utils.DerivedChargersKey(attrs.Tenant, attrs.Category, attrs.Direction, attrs.Account, attrs.Subject), nil); err != nil {
|
||||
return fmt.Errorf("%s:%s", utils.ERR_SERVER_ERROR, err.Error())
|
||||
} else {
|
||||
*reply = "OK"
|
||||
}
|
||||
return nil
|
||||
}
|
||||
*/
|
||||
|
||||
@@ -27,8 +27,8 @@ import (
|
||||
func HandleGetDerivedChargers(acntStorage AccountingStorage, cfg *config.CGRConfig, attrs utils.AttrDerivedChargers) (utils.DerivedChargers, error) {
|
||||
var dcs utils.DerivedChargers
|
||||
var err error
|
||||
strictKey := utils.DerivedChargersKey(attrs.Tenant, attrs.Tor, attrs.Direction, attrs.Account, attrs.Subject)
|
||||
anySubjKey := utils.DerivedChargersKey(attrs.Tenant, attrs.Tor, attrs.Direction, attrs.Account, utils.ANY)
|
||||
strictKey := utils.DerivedChargersKey(attrs.Direction, attrs.Tenant, attrs.Category, attrs.Account, attrs.Subject)
|
||||
anySubjKey := utils.DerivedChargersKey(attrs.Direction, attrs.Tenant, attrs.Category, attrs.Account, utils.ANY)
|
||||
for _, dcKey := range []string{strictKey, anySubjKey} {
|
||||
if dcsDb, err := acntStorage.GetDerivedChargers(dcKey, false); err != nil && err.Error() != utils.ERR_NOT_FOUND {
|
||||
return nil, err
|
||||
|
||||
@@ -59,7 +59,7 @@ func TestHandleGetConfiguredDC(t *testing.T) {
|
||||
|
||||
// Receive composed derived chargers
|
||||
func TestHandleGetStoredDC(t *testing.T) {
|
||||
keyCharger1 := utils.DerivedChargersKey("cgrates.org", "call", "*out", "rif", "rif")
|
||||
keyCharger1 := utils.DerivedChargersKey("*out", "cgrates.org", "call", "rif", "rif")
|
||||
charger1 := utils.DerivedChargers{
|
||||
&utils.DerivedCharger{RunId: "extra1", ReqTypeField: "^prepaid", DirectionField: "*default", TenantField: "*default", TorField: "*default",
|
||||
AccountField: "rif", SubjectField: "rif", DestinationField: "*default", SetupTimeField: "*default", AnswerTimeField: "*default", DurationField: "*default"},
|
||||
|
||||
@@ -168,10 +168,10 @@ vdf,emptyY,*out,TOPUP_EMPTY_AT,
|
||||
`
|
||||
|
||||
derivedCharges = `
|
||||
#Tenant,Tor,Direction,Account,Subject,RunId,ReqTypeField,DirectionField,TenantField,TorField,AccountField,SubjectField,DestinationField,SetupTimeField,AnswerTimeField,DurationField
|
||||
cgrates.org,call,*out,dan,dan,extra1,^prepaid,,,,rif,rif,,,,
|
||||
cgrates.org,call,*out,dan,dan,extra2,,,,,ivo,ivo,,,,
|
||||
cgrates.org,call,*out,dan,*any,extra1,,,,,rif2,rif2,,,,
|
||||
#Direction,Tenant,Category,Account,Subject,RunId,ReqTypeField,DirectionField,TenantField,TorField,AccountField,SubjectField,DestinationField,SetupTimeField,AnswerTimeField,DurationField
|
||||
*out,cgrates.org,call,dan,dan,extra1,^prepaid,,,,rif,rif,,,,
|
||||
*out,cgrates.org,call,dan,dan,extra2,,,,,ivo,ivo,,,,
|
||||
*out,cgrates.org,call,dan,*any,extra1,,,,,rif2,rif2,,,,
|
||||
`
|
||||
)
|
||||
|
||||
|
||||
@@ -114,8 +114,8 @@ func (self *Mediator) RateCdr(dbcdr utils.RawCDR) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
cdrs := []*utils.StoredCdr{rtCdr} // Start with initial dbcdr, will add here all to be mediated
|
||||
attrsDC := utils.AttrDerivedChargers{Tenant: rtCdr.Tenant, Tor: rtCdr.TOR, Direction: rtCdr.Direction,
|
||||
cdrs := []*utils.StoredCdr{rtCdr} // Start with initial dbcdr, will add here all to be mediated
|
||||
attrsDC := utils.AttrDerivedChargers{Direction: rtCdr.Direction, Tenant: rtCdr.Tenant, Category: rtCdr.TOR,
|
||||
Account: rtCdr.Account, Subject: rtCdr.Subject}
|
||||
var dcs utils.DerivedChargers
|
||||
if err := self.connector.GetDerivedChargers(attrsDC, &dcs); err != nil {
|
||||
|
||||
@@ -151,7 +151,7 @@ func (sm *FSSessionManager) OnHeartBeat(ev Event) {
|
||||
func (sm *FSSessionManager) OnChannelPark(ev Event) {
|
||||
var maxCallDuration time.Duration // This will be the maximum duration this channel will be allowed to last
|
||||
var durInitialized bool
|
||||
attrsDC := utils.AttrDerivedChargers{Tenant: ev.GetTenant(utils.META_DEFAULT), Tor: ev.GetTOR(utils.META_DEFAULT), Direction: ev.GetDirection(utils.META_DEFAULT),
|
||||
attrsDC := utils.AttrDerivedChargers{Tenant: ev.GetTenant(utils.META_DEFAULT), Category: ev.GetTOR(utils.META_DEFAULT), Direction: ev.GetDirection(utils.META_DEFAULT),
|
||||
Account: ev.GetAccount(utils.META_DEFAULT), Subject: ev.GetSubject(utils.META_DEFAULT)}
|
||||
var dcs utils.DerivedChargers
|
||||
if err := sm.connector.GetDerivedChargers(attrsDC, &dcs); err != nil {
|
||||
@@ -219,7 +219,7 @@ func (sm *FSSessionManager) OnChannelAnswer(ev Event) {
|
||||
if _, err := fsock.FS.SendApiCmd(fmt.Sprintf("uuid_setvar %s cgr_reqtype %s\n\n", ev.GetUUID(), ev.GetReqType(""))); err != nil {
|
||||
engine.Logger.Err(fmt.Sprintf("Error on attempting to overwrite cgr_type in chan variables: %v", err))
|
||||
}
|
||||
attrsDC := utils.AttrDerivedChargers{Tenant: ev.GetTenant(utils.META_DEFAULT), Tor: ev.GetTOR(utils.META_DEFAULT),
|
||||
attrsDC := utils.AttrDerivedChargers{Tenant: ev.GetTenant(utils.META_DEFAULT), Category: ev.GetTOR(utils.META_DEFAULT),
|
||||
Direction: ev.GetDirection(utils.META_DEFAULT), Account: ev.GetAccount(utils.META_DEFAULT), Subject: ev.GetSubject(utils.META_DEFAULT)}
|
||||
var dcs utils.DerivedChargers
|
||||
if err := sm.connector.GetDerivedChargers(attrsDC, &dcs); err != nil {
|
||||
@@ -242,7 +242,7 @@ func (sm *FSSessionManager) OnChannelHangupComplete(ev Event) {
|
||||
sm.RemoveSession(s.uuid) // Unreference it early so we avoid concurrency
|
||||
}
|
||||
defer s.Close(ev) // Stop loop and save the costs deducted so far to database
|
||||
attrsDC := utils.AttrDerivedChargers{Tenant: ev.GetTenant(utils.META_DEFAULT), Tor: ev.GetTOR(utils.META_DEFAULT), Direction: ev.GetDirection(utils.META_DEFAULT),
|
||||
attrsDC := utils.AttrDerivedChargers{Tenant: ev.GetTenant(utils.META_DEFAULT), Category: ev.GetTOR(utils.META_DEFAULT), Direction: ev.GetDirection(utils.META_DEFAULT),
|
||||
Account: ev.GetAccount(utils.META_DEFAULT), Subject: ev.GetSubject(utils.META_DEFAULT)}
|
||||
var dcs utils.DerivedChargers
|
||||
if err := sm.connector.GetDerivedChargers(attrsDC, &dcs); err != nil {
|
||||
|
||||
@@ -379,5 +379,5 @@ type AttrGetDestination struct {
|
||||
}
|
||||
|
||||
type AttrDerivedChargers struct {
|
||||
Tenant, Tor, Direction, Account, Subject string
|
||||
Direction, Tenant, Category, Account, Subject string
|
||||
}
|
||||
|
||||
@@ -116,8 +116,8 @@ type DerivedCharger struct {
|
||||
rsrDurationField *RSRField
|
||||
}
|
||||
|
||||
func DerivedChargersKey(tenant, tor, direction, account, subject string) string {
|
||||
return ConcatenatedKey(tenant, tor, direction, account, subject)
|
||||
func DerivedChargersKey(direction, tenant, category, account, subject string) string {
|
||||
return ConcatenatedKey(direction, tenant, category, account, subject)
|
||||
}
|
||||
|
||||
type DerivedChargers []*DerivedCharger
|
||||
|
||||
@@ -105,7 +105,7 @@ func TestNewDerivedCharger(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestDerivedChargersKey(t *testing.T) {
|
||||
if dcKey := DerivedChargersKey("cgrates.org", "call", "*out", "dan", "dan"); dcKey != "cgrates.org:call:*out:dan:dan" {
|
||||
if dcKey := DerivedChargersKey("*out", "cgrates.org", "call", "dan", "dan"); dcKey != "*out:cgrates.org:call:dan:dan" {
|
||||
t.Error("Unexpected derived chargers key: ", dcKey)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user