From 90069ab05db1def02280fcb0b0971d48e76a00a1 Mon Sep 17 00:00:00 2001 From: DanB Date: Mon, 29 Aug 2016 12:57:24 +0200 Subject: [PATCH] AccountDigest - AccountSummary for better readability --- config/config.go | 6 +++--- config/config_defaults.go | 2 +- config/config_json_test.go | 8 ++++---- config/libconfig_json.go | 20 ++++++++++---------- engine/account.go | 18 +++++++++--------- engine/account_test.go | 32 ++++++++++++++++---------------- engine/balances.go | 6 +++--- engine/callcost.go | 2 +- engine/cdrs.go | 4 ++-- 9 files changed, 49 insertions(+), 49 deletions(-) diff --git a/config/config.go b/config/config.go index 76d7eb98b..8553b098c 100644 --- a/config/config.go +++ b/config/config.go @@ -228,7 +228,7 @@ type CGRConfig struct { CDRSEnabled bool // Enable CDR Server service CDRSExtraFields []*utils.RSRField // Extra fields to store in CDRs CDRSStoreCdrs bool // store cdrs in storDb - CDRScdrAccountDigest bool + CDRScdrAccountSummary bool CDRSRaterConns []*HaPoolConfig // address where to reach the Rater for cost calculation: <""|internal|x.y.z.y:1234> CDRSPubSubSConns []*HaPoolConfig // address where to reach the pubsub service: <""|internal|x.y.z.y:1234> CDRSUserSConns []*HaPoolConfig // address where to reach the users service: <""|internal|x.y.z.y:1234> @@ -817,8 +817,8 @@ func (self *CGRConfig) loadFromJsonCfg(jsnCfg *CgrJsonCfg) error { if jsnCdrsCfg.Store_cdrs != nil { self.CDRSStoreCdrs = *jsnCdrsCfg.Store_cdrs } - if jsnCdrsCfg.Cdr_account_digest != nil { - self.CDRScdrAccountDigest = *jsnCdrsCfg.Cdr_account_digest + if jsnCdrsCfg.Cdr_account_summary != nil { + self.CDRScdrAccountSummary = *jsnCdrsCfg.Cdr_account_summary } if jsnCdrsCfg.Rals_conns != nil { self.CDRSRaterConns = make([]*HaPoolConfig, len(*jsnCdrsCfg.Rals_conns)) diff --git a/config/config_defaults.go b/config/config_defaults.go index 287d45d5f..d50b36446 100644 --- a/config/config_defaults.go +++ b/config/config_defaults.go @@ -132,7 +132,7 @@ const CGRATES_CFG_JSON = ` "enabled": false, // start the CDR Server service: "extra_fields": [], // extra fields to store in CDRs for non-generic CDRs "store_cdrs": true, // store cdrs in storDb - "cdr_account_digest": false, // add account information from dataDB + "cdr_account_summary": false, // add account information from dataDB "rals_conns": [ {"address": "*internal"} // address where to reach the Rater for cost calculation, empty to disable functionality: <""|*internal|x.y.z.y:1234> ], diff --git a/config/config_json_test.go b/config/config_json_test.go index 6609ffadd..84df09550 100644 --- a/config/config_json_test.go +++ b/config/config_json_test.go @@ -174,10 +174,10 @@ func TestDfSchedulerJsonCfg(t *testing.T) { func TestDfCdrsJsonCfg(t *testing.T) { eCfg := &CdrsJsonCfg{ - Enabled: utils.BoolPointer(false), - Extra_fields: utils.StringSlicePointer([]string{}), - Store_cdrs: utils.BoolPointer(true), - Cdr_account_digest: utils.BoolPointer(false), + Enabled: utils.BoolPointer(false), + Extra_fields: utils.StringSlicePointer([]string{}), + Store_cdrs: utils.BoolPointer(true), + Cdr_account_summary: utils.BoolPointer(false), Rals_conns: &[]*HaPoolJsonCfg{ &HaPoolJsonCfg{ Address: utils.StringPointer("*internal"), diff --git a/config/libconfig_json.go b/config/libconfig_json.go index abceb7211..3ee619db0 100644 --- a/config/libconfig_json.go +++ b/config/libconfig_json.go @@ -85,16 +85,16 @@ type SchedulerJsonCfg struct { // Cdrs config section type CdrsJsonCfg struct { - Enabled *bool - Extra_fields *[]string - Store_cdrs *bool - Cdr_account_digest *bool - Rals_conns *[]*HaPoolJsonCfg - Pubsubs_conns *[]*HaPoolJsonCfg - Users_conns *[]*HaPoolJsonCfg - Aliases_conns *[]*HaPoolJsonCfg - Cdrstats_conns *[]*HaPoolJsonCfg - Cdr_replication *[]*CdrReplicationJsonCfg + Enabled *bool + Extra_fields *[]string + Store_cdrs *bool + Cdr_account_summary *bool + Rals_conns *[]*HaPoolJsonCfg + Pubsubs_conns *[]*HaPoolJsonCfg + Users_conns *[]*HaPoolJsonCfg + Aliases_conns *[]*HaPoolJsonCfg + Cdrstats_conns *[]*HaPoolJsonCfg + Cdr_replication *[]*CdrReplicationJsonCfg } type CdrReplicationJsonCfg struct { diff --git a/engine/account.go b/engine/account.go index 928859871..418b316ce 100644 --- a/engine/account.go +++ b/engine/account.go @@ -1019,9 +1019,9 @@ func (acc *Account) AsOldStructure() interface{} { return result } -func (acc *Account) AsAccountDigest() *AccountDigest { +func (acc *Account) AsAccountSummary() *AccountSummary { idSplt := strings.Split(acc.ID, utils.CONCATENATED_KEY_SEP) - ad := &AccountDigest{AllowNegative: acc.AllowNegative, Disabled: acc.Disabled} + ad := &AccountSummary{AllowNegative: acc.AllowNegative, Disabled: acc.Disabled} if len(idSplt) == 1 { ad.ID = idSplt[0] } else if len(idSplt) == 2 { @@ -1030,17 +1030,17 @@ func (acc *Account) AsAccountDigest() *AccountDigest { } for balanceType, balances := range acc.BalanceMap { for _, balance := range balances { - ad.BalanceDigests = append(ad.BalanceDigests, balance.AsBalanceDigest(balanceType)) + ad.BalanceSummaries = append(ad.BalanceSummaries, balance.AsBalanceSummary(balanceType)) } } return ad } // AccountDigest contains compressed information about an Account -type AccountDigest struct { - Tenant string - ID string - BalanceDigests []*BalanceDigest - AllowNegative bool - Disabled bool +type AccountSummary struct { + Tenant string + ID string + BalanceSummaries []*BalanceSummary + AllowNegative bool + Disabled bool } diff --git a/engine/account_test.go b/engine/account_test.go index b247d9700..1110557df 100644 --- a/engine/account_test.go +++ b/engine/account_test.go @@ -1886,30 +1886,30 @@ func TestAccountAsAccountDigest(t *testing.T) { }, }, } - expectAcntDigest := &AccountDigest{ + expectacntSummary := &AccountSummary{ Tenant: "cgrates.org", ID: "account1", - BalanceDigests: []*BalanceDigest{ - &BalanceDigest{ID: "sms1", Type: utils.SMS, Value: 14, Disabled: false}, - &BalanceDigest{ID: "data1", Type: utils.DATA, Value: 1204, Disabled: false}, - &BalanceDigest{ID: "voice1", Type: utils.VOICE, Value: 1204, Disabled: false}, - &BalanceDigest{ID: "voice2", Type: utils.VOICE, Value: 1200, Disabled: false}, + BalanceSummaries: []*BalanceSummary{ + &BalanceSummary{ID: "sms1", Type: utils.SMS, Value: 14, Disabled: false}, + &BalanceSummary{ID: "data1", Type: utils.DATA, Value: 1204, Disabled: false}, + &BalanceSummary{ID: "voice1", Type: utils.VOICE, Value: 1204, Disabled: false}, + &BalanceSummary{ID: "voice2", Type: utils.VOICE, Value: 1200, Disabled: false}, }, AllowNegative: true, Disabled: false, } - acntDigest := acnt1.AsAccountDigest() - if expectAcntDigest.Tenant != acntDigest.Tenant || - expectAcntDigest.ID != acntDigest.ID || - expectAcntDigest.AllowNegative != acntDigest.AllowNegative || - expectAcntDigest.Disabled != acntDigest.Disabled || - len(expectAcntDigest.BalanceDigests) != len(acntDigest.BalanceDigests) { - t.Errorf("Expecting: %+v, received: %+v", expectAcntDigest, acntDigest) + acntSummary := acnt1.AsAccountSummary() + if expectacntSummary.Tenant != acntSummary.Tenant || + expectacntSummary.ID != acntSummary.ID || + expectacntSummary.AllowNegative != acntSummary.AllowNegative || + expectacntSummary.Disabled != acntSummary.Disabled || + len(expectacntSummary.BalanceSummaries) != len(acntSummary.BalanceSummaries) { + t.Errorf("Expecting: %+v, received: %+v", expectacntSummary, acntSummary) } // Since maps are unordered, slices will be too so we need to find element to compare - for _, bd := range acntDigest.BalanceDigests { - if bd.ID == "sms1" && !reflect.DeepEqual(expectAcntDigest.BalanceDigests[0], bd) { - t.Errorf("Expecting: %+v, received: %+v", expectAcntDigest, acntDigest) + for _, bd := range acntSummary.BalanceSummaries { + if bd.ID == "sms1" && !reflect.DeepEqual(expectacntSummary.BalanceSummaries[0], bd) { + t.Errorf("Expecting: %+v, received: %+v", expectacntSummary, acntSummary) } } } diff --git a/engine/balances.go b/engine/balances.go index 235bac51a..5da03ec59 100644 --- a/engine/balances.go +++ b/engine/balances.go @@ -621,8 +621,8 @@ func (b *Balance) debitMoney(cd *CallDescriptor, ub *Account, moneyBalances Bala } // Converts the balance towards compressed information to be displayed -func (b *Balance) AsBalanceDigest(typ string) *BalanceDigest { - bd := &BalanceDigest{ID: b.ID, Type: typ, Value: b.Value, Disabled: b.Disabled} +func (b *Balance) AsBalanceSummary(typ string) *BalanceSummary { + bd := &BalanceSummary{ID: b.ID, Type: typ, Value: b.Value, Disabled: b.Disabled} if bd.ID == "" { bd.ID = b.Uuid } @@ -752,7 +752,7 @@ func (f ValueFactor) GetValue(tor string) float64 { } // BalanceDigest represents compressed information about a balance -type BalanceDigest struct { +type BalanceSummary struct { ID string // ID or UUID if not defined Type string // *voice, *data, etc Value float64 diff --git a/engine/callcost.go b/engine/callcost.go index be26634cd..787723b96 100644 --- a/engine/callcost.go +++ b/engine/callcost.go @@ -30,7 +30,7 @@ type CallCost struct { Cost float64 Timespans TimeSpans RatedUsage float64 - AccountDigest *AccountDigest + AccountSummary *AccountSummary deductConnectFee bool negativeConnectFee bool // the connect fee went negative on default balance maxCostDisconect bool diff --git a/engine/cdrs.go b/engine/cdrs.go index 89df840f3..5b5f70d59 100644 --- a/engine/cdrs.go +++ b/engine/cdrs.go @@ -246,13 +246,13 @@ func (self *CdrServer) deriveRateStoreStatsReplicate(cdr *CDR, store, stats, rep ratedCDR.CostDetails.UpdateCost() ratedCDR.CostDetails.UpdateRatedUsage() if utils.IsSliceMember([]string{utils.META_PREPAID, utils.PREPAID, utils.META_PSEUDOPREPAID, utils.PSEUDOPREPAID, - utils.META_POSTPAID, utils.POSTPAID}, ratedCDR.RequestType) && self.cgrCfg.CDRScdrAccountDigest { + utils.META_POSTPAID, utils.POSTPAID}, ratedCDR.RequestType) && self.cgrCfg.CDRScdrAccountSummary { acntID := utils.ConcatenatedKey(ratedCDR.Tenant, ratedCDR.Account) acnt, err := self.dataDB.GetAccount(acntID) if err != nil { utils.Logger.Err(fmt.Sprintf(" Querying AccountDigest for account: %s got error: %s", acntID, err.Error())) } else if acnt.ID != "" { - ratedCDR.CostDetails.AccountDigest = acnt.AsAccountDigest() + ratedCDR.CostDetails.AccountSummary = acnt.AsAccountSummary() } } }