normal test passing

This commit is contained in:
Radu Ioan Fericean
2015-06-16 19:45:01 +03:00
parent 61d9919df6
commit fcb5fee2fc
51 changed files with 924 additions and 861 deletions

View File

@@ -61,7 +61,7 @@ func (ub *Account) getCreditForPrefix(cd *CallDescriptor) (duration time.Duratio
var extendedCreditBalances BalanceChain
for _, cb := range creditBalances {
if cb.SharedGroup != "" {
if sharedGroup, _ := accountingStorage.GetSharedGroup(cb.SharedGroup, false); sharedGroup != nil {
if sharedGroup, _ := ratingStorage.GetSharedGroup(cb.SharedGroup, false); sharedGroup != nil {
sgb := sharedGroup.GetBalances(cd.Destination, cd.Category, utils.MONETARY+cd.Direction, ub)
sgb = sharedGroup.SortBalancesByStrategy(cb, sgb)
extendedCreditBalances = append(extendedCreditBalances, sgb...)
@@ -73,7 +73,7 @@ func (ub *Account) getCreditForPrefix(cd *CallDescriptor) (duration time.Duratio
var extendedMinuteBalances BalanceChain
for _, mb := range unitBalances {
if mb.SharedGroup != "" {
if sharedGroup, _ := accountingStorage.GetSharedGroup(mb.SharedGroup, false); sharedGroup != nil {
if sharedGroup, _ := ratingStorage.GetSharedGroup(mb.SharedGroup, false); sharedGroup != nil {
sgb := sharedGroup.GetBalances(cd.Destination, cd.Category, cd.TOR+cd.Direction, ub)
sgb = sharedGroup.SortBalancesByStrategy(mb, sgb)
extendedMinuteBalances = append(extendedMinuteBalances, sgb...)
@@ -131,7 +131,7 @@ func (ub *Account) debitBalanceAction(a *Action, reset bool) error {
}
if a.Balance.SharedGroup != "" {
// add shared group member
sg, err := accountingStorage.GetSharedGroup(a.Balance.SharedGroup, false)
sg, err := ratingStorage.GetSharedGroup(a.Balance.SharedGroup, false)
if err != nil || sg == nil {
//than problem
Logger.Warning(fmt.Sprintf("Could not get shared group: %v", a.Balance.SharedGroup))
@@ -139,7 +139,7 @@ func (ub *Account) debitBalanceAction(a *Action, reset bool) error {
if !utils.IsSliceMember(sg.MemberIds, ub.Id) {
// add member and save
sg.MemberIds = append(sg.MemberIds, ub.Id)
accountingStorage.SetSharedGroup(sg)
ratingStorage.SetSharedGroup(sg)
}
}
}
@@ -162,7 +162,7 @@ func (ub *Account) getBalancesForPrefix(prefix, category string, balances Balanc
b.account = ub
if b.DestinationIds != "" && b.DestinationIds != utils.ANY {
for _, p := range utils.SplitPrefix(prefix, MIN_PREFIX_MATCH) {
if x, err := cache2go.GetCached(DESTINATION_PREFIX + p); err == nil {
if x, err := cache2go.GetCached(utils.DESTINATION_PREFIX + p); err == nil {
destIds := x.(map[interface{}]struct{})
for dId, _ := range destIds {
balDestIds := strings.Split(b.DestinationIds, utils.INFIELD_SEP)
@@ -200,7 +200,7 @@ func (account *Account) getAlldBalancesForPrefix(destination, category, balanceT
balances := account.getBalancesForPrefix(destination, category, account.BalanceMap[balanceType], "")
for _, b := range balances {
if b.SharedGroup != "" {
sharedGroup, err := accountingStorage.GetSharedGroup(b.SharedGroup, false)
sharedGroup, err := ratingStorage.GetSharedGroup(b.SharedGroup, false)
if err != nil {
Logger.Warning(fmt.Sprintf("Could not get shared group: %v", b.SharedGroup))
continue
@@ -516,7 +516,7 @@ func (ub *Account) countUnits(a *Action) {
func (ub *Account) initCounters() {
ucTempMap := make(map[string]*UnitsCounter, 2)
for _, at := range ub.ActionTriggers {
acs, err := accountingStorage.GetActions(at.ActionsId, false)
acs, err := ratingStorage.GetActions(at.ActionsId, false)
if err != nil {
continue
}
@@ -590,7 +590,7 @@ func (account *Account) GetUniqueSharedGroupMembers(cd *CallDescriptor) ([]strin
}
var memberIds []string
for _, sgID := range sharedGroupIds {
sharedGroup, err := accountingStorage.GetSharedGroup(sgID, false)
sharedGroup, err := ratingStorage.GetSharedGroup(sgID, false)
if err != nil {
Logger.Warning(fmt.Sprintf("Could not get shared group: %v", sgID))
return nil, err

View File

@@ -1172,8 +1172,8 @@ func TestDebitShared(t *testing.T) {
sg := &SharedGroup{Id: "SG_TEST", MemberIds: []string{rif.Id, groupie.Id}, AccountParameters: map[string]*SharingParameters{"*any": &SharingParameters{Strategy: STRATEGY_MINE_RANDOM}}}
accountingStorage.SetAccount(groupie)
accountingStorage.SetSharedGroup(sg)
cache2go.Cache(SHARED_GROUP_PREFIX+"SG_TEST", sg)
ratingStorage.SetSharedGroup(sg)
cache2go.Cache(utils.SHARED_GROUP_PREFIX+"SG_TEST", sg)
cc, err := rif.debitCreditBalance(cd, false, false, true)
if err != nil {
t.Error("Error debiting balance: ", err)
@@ -1242,8 +1242,8 @@ func TestMaxDurationShared(t *testing.T) {
sg := &SharedGroup{Id: "SG_TEST", MemberIds: []string{rif.Id, groupie.Id}, AccountParameters: map[string]*SharingParameters{"*any": &SharingParameters{Strategy: STRATEGY_MINE_RANDOM}}}
accountingStorage.SetAccount(groupie)
accountingStorage.SetSharedGroup(sg)
cache2go.Cache(SHARED_GROUP_PREFIX+"SG_TEST", sg)
ratingStorage.SetSharedGroup(sg)
cache2go.Cache(utils.SHARED_GROUP_PREFIX+"SG_TEST", sg)
duration, err := cd.getMaxSessionDuration(rif)
if err != nil {
t.Error("Error getting max session duration from shared group: ", err)

View File

@@ -228,7 +228,7 @@ func (at *ActionPlan) SetActions(as Actions) {
func (at *ActionPlan) getActions() (as []*Action, err error) {
if at.actions == nil {
at.actions, err = accountingStorage.GetActions(at.ActionsId, false)
at.actions, err = ratingStorage.GetActions(at.ActionsId, false)
}
at.actions.Sort()
return at.actions, err
@@ -275,7 +275,7 @@ func (at *ActionPlan) Execute() (err error) {
}
}
}
storageLogger.LogActionPlan(SCHED_SOURCE, at, aac)
storageLogger.LogActionPlan(utils.SCHED_SOURCE, at, aac)
return
}

View File

@@ -64,7 +64,7 @@ func (at *ActionTrigger) Execute(ub *Account, sq *StatsQueueTriggered) (err erro
}
// does NOT need to Lock() because it is triggered from a method that took the Lock
var aac Actions
aac, err = accountingStorage.GetActions(at.ActionsId, false)
aac, err = ratingStorage.GetActions(at.ActionsId, false)
aac.Sort()
if err != nil {
Logger.Err(fmt.Sprintf("Failed to get actions: %v", err))
@@ -92,7 +92,7 @@ func (at *ActionTrigger) Execute(ub *Account, sq *StatsQueueTriggered) (err erro
at.Executed = false
}
if ub != nil {
storageLogger.LogActionTrigger(ub.Id, RATER_SOURCE, at, aac)
storageLogger.LogActionTrigger(ub.Id, utils.RATER_SOURCE, at, aac)
accountingStorage.SetAccount(ub)
}
return

View File

@@ -988,14 +988,14 @@ func TestActionTriggerLogging(t *testing.T) {
Weight: 10.0,
ActionsId: "TEST_ACTIONS",
}
as, err := accountingStorage.GetActions(at.ActionsId, false)
as, err := ratingStorage.GetActions(at.ActionsId, false)
if err != nil {
t.Error("Error getting actions for the action timing: ", as, err)
}
storageLogger.LogActionTrigger("rif", RATER_SOURCE, at, as)
storageLogger.LogActionTrigger("rif", utils.RATER_SOURCE, at, as)
//expected := "rif*some_uuid;MONETARY;OUT;NAT;TEST_ACTIONS;100;10;false*|TOPUP|MONETARY|OUT|10|0"
var key string
atMap, _ := accountingStorage.GetAllActionPlans()
atMap, _ := ratingStorage.GetAllActionPlans()
for k, v := range atMap {
_ = k
_ = v
@@ -1032,14 +1032,14 @@ func TestActionPlanLogging(t *testing.T) {
Weight: 10.0,
ActionsId: "TEST_ACTIONS",
}
as, err := accountingStorage.GetActions(at.ActionsId, false)
as, err := ratingStorage.GetActions(at.ActionsId, false)
if err != nil {
t.Error("Error getting actions for the action trigger: ", err)
}
storageLogger.LogActionPlan(SCHED_SOURCE, at, as)
storageLogger.LogActionPlan(utils.SCHED_SOURCE, at, as)
//expected := "some uuid|test|one,two,three|;1,2,3,4,5,6,7,8,9,10,11,12;1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31;1,2,3,4,5;18:00:00;00:00:00;10;0;1;60;1|10|TEST_ACTIONS*|TOPUP|MONETARY|OUT|10|0"
var key string
atMap, _ := accountingStorage.GetAllActionPlans()
atMap, _ := ratingStorage.GetAllActionPlans()
for k, v := range atMap {
_ = k
_ = v

View File

@@ -281,7 +281,7 @@ func (cd *CallDescriptor) addRatingInfos(ris RatingInfos) bool {
// The prefixLen is limiting the length of the destination prefix.
func (cd *CallDescriptor) GetKey(subject string) string {
// check if subject is alias
if rs, err := cache2go.GetCached(RP_ALIAS_PREFIX + utils.RatingSubjectAliasKey(cd.Tenant, subject)); err == nil {
if rs, err := cache2go.GetCached(utils.RP_ALIAS_PREFIX + utils.RatingSubjectAliasKey(cd.Tenant, subject)); err == nil {
realSubject := rs.(string)
subject = realSubject
cd.Subject = realSubject
@@ -294,7 +294,7 @@ func (cd *CallDescriptor) GetAccountKey() string {
subj := cd.Subject
if cd.Account != "" {
// check if subject is alias
if realSubject, err := cache2go.GetCached(ACC_ALIAS_PREFIX + utils.AccountAliasKey(cd.Tenant, subj)); err == nil {
if realSubject, err := cache2go.GetCached(utils.ACC_ALIAS_PREFIX + utils.AccountAliasKey(cd.Tenant, subj)); err == nil {
cd.Account = realSubject.(string)
}
subj = cd.Account
@@ -667,8 +667,7 @@ func (cd *CallDescriptor) RefundIncrements() (left float64, err error) {
func (cd *CallDescriptor) FlushCache() (err error) {
cache2go.Flush()
ratingStorage.CacheRating(nil, nil, nil, nil, nil, nil)
accountingStorage.CacheAccounting(nil, nil, nil)
ratingStorage.CacheAll()
return nil
}
@@ -800,7 +799,7 @@ func (cd *CallDescriptor) GetLCR(stats StatsInterface) (*LCRCost, error) {
}
ratingProfileSearchKey := utils.ConcatenatedKey(lcr.Direction, lcr.Tenant, lcrCost.Entry.RPCategory)
//log.Print("KEY: ", ratingProfileSearchKey)
suppliers := cache2go.GetEntriesKeys(RATING_PROFILE_PREFIX + ratingProfileSearchKey)
suppliers := cache2go.GetEntriesKeys(utils.RATING_PROFILE_PREFIX + ratingProfileSearchKey)
for _, supplier := range suppliers {
//log.Print("Supplier: ", supplier)
split := strings.Split(supplier, ":")

View File

@@ -94,9 +94,9 @@ func populateDB() {
&Balance{Value: 11, Weight: 20},
}},
}
if accountingStorage != nil {
accountingStorage.SetActions("TEST_ACTIONS", ats)
accountingStorage.SetActions("TEST_ACTIONS_ORDER", ats1)
if accountingStorage != nil && ratingStorage != nil {
ratingStorage.SetActions("TEST_ACTIONS", ats)
ratingStorage.SetActions("TEST_ACTIONS_ORDER", ats1)
accountingStorage.SetAccount(broker)
accountingStorage.SetAccount(minu)
accountingStorage.SetAccount(minitsboy)
@@ -468,7 +468,7 @@ func TestMaxSessionTimeWithAccount(t *testing.T) {
}
func TestMaxSessionTimeWithMaxRate(t *testing.T) {
ap, _ := accountingStorage.GetActionPlans("TOPUP10_AT")
ap, _ := ratingStorage.GetActionPlans("TOPUP10_AT")
for _, at := range ap {
at.Execute()
}
@@ -492,7 +492,7 @@ func TestMaxSessionTimeWithMaxRate(t *testing.T) {
}
func TestMaxSessionTimeWithMaxCost(t *testing.T) {
ap, _ := accountingStorage.GetActionPlans("TOPUP10_AT")
ap, _ := ratingStorage.GetActionPlans("TOPUP10_AT")
for _, at := range ap {
at.Execute()
}
@@ -515,7 +515,7 @@ func TestMaxSessionTimeWithMaxCost(t *testing.T) {
}
func TestGetCostWithMaxCost(t *testing.T) {
ap, _ := accountingStorage.GetActionPlans("TOPUP10_AT")
ap, _ := ratingStorage.GetActionPlans("TOPUP10_AT")
for _, at := range ap {
at.Execute()
}
@@ -538,7 +538,7 @@ func TestGetCostWithMaxCost(t *testing.T) {
}
func TestMaxSessionTimeWithMaxCostFree(t *testing.T) {
ap, _ := accountingStorage.GetActionPlans("TOPUP10_AT")
ap, _ := ratingStorage.GetActionPlans("TOPUP10_AT")
for _, at := range ap {
at.Execute()
}
@@ -561,7 +561,7 @@ func TestMaxSessionTimeWithMaxCostFree(t *testing.T) {
}
func TestMaxDebitWithMaxCostFree(t *testing.T) {
ap, _ := accountingStorage.GetActionPlans("TOPUP10_AT")
ap, _ := ratingStorage.GetActionPlans("TOPUP10_AT")
for _, at := range ap {
at.Execute()
}
@@ -584,7 +584,7 @@ func TestMaxDebitWithMaxCostFree(t *testing.T) {
}
func TestGetCostWithMaxCostFree(t *testing.T) {
ap, _ := accountingStorage.GetActionPlans("TOPUP10_AT")
ap, _ := ratingStorage.GetActionPlans("TOPUP10_AT")
for _, at := range ap {
at.Execute()
}
@@ -626,11 +626,11 @@ func TestMaxSessionTimeWithAccountAlias(t *testing.T) {
}
func TestMaxSessionTimeWithAccountShared(t *testing.T) {
ap, _ := accountingStorage.GetActionPlans("TOPUP_SHARED0_AT")
ap, _ := ratingStorage.GetActionPlans("TOPUP_SHARED0_AT")
for _, at := range ap {
at.Execute()
}
ap, _ = accountingStorage.GetActionPlans("TOPUP_SHARED10_AT")
ap, _ = ratingStorage.GetActionPlans("TOPUP_SHARED10_AT")
for _, at := range ap {
at.Execute()
}
@@ -665,11 +665,11 @@ func TestMaxSessionTimeWithAccountShared(t *testing.T) {
}
func TestMaxDebitWithAccountShared(t *testing.T) {
ap, _ := accountingStorage.GetActionPlans("TOPUP_SHARED0_AT")
ap, _ := ratingStorage.GetActionPlans("TOPUP_SHARED0_AT")
for _, at := range ap {
at.Execute()
}
ap, _ = accountingStorage.GetActionPlans("TOPUP_SHARED10_AT")
ap, _ = ratingStorage.GetActionPlans("TOPUP_SHARED10_AT")
for _, at := range ap {
at.Execute()
}
@@ -851,7 +851,7 @@ func TestMaxSesionTimeEmptyBalanceAndNoCost(t *testing.T) {
}
func TestDebitFromShareAndNormal(t *testing.T) {
ap, _ := accountingStorage.GetActionPlans("TOPUP_SHARED10_AT")
ap, _ := ratingStorage.GetActionPlans("TOPUP_SHARED10_AT")
for _, at := range ap {
at.Execute()
}
@@ -879,7 +879,7 @@ func TestDebitFromShareAndNormal(t *testing.T) {
}
func TestDebitFromEmptyShare(t *testing.T) {
ap, _ := accountingStorage.GetActionPlans("TOPUP_EMPTY_AT")
ap, _ := ratingStorage.GetActionPlans("TOPUP_EMPTY_AT")
for _, at := range ap {
at.Execute()
}
@@ -907,7 +907,7 @@ func TestDebitFromEmptyShare(t *testing.T) {
}
func TestMaxDebitZeroDefinedRate(t *testing.T) {
ap, _ := accountingStorage.GetActionPlans("TOPUP10_AT")
ap, _ := ratingStorage.GetActionPlans("TOPUP10_AT")
for _, at := range ap {
at.Execute()
}
@@ -935,7 +935,7 @@ func TestMaxDebitZeroDefinedRate(t *testing.T) {
}
func TestMaxDebitZeroDefinedRateOnlyMinutes(t *testing.T) {
ap, _ := accountingStorage.GetActionPlans("TOPUP10_AT")
ap, _ := ratingStorage.GetActionPlans("TOPUP10_AT")
for _, at := range ap {
at.Execute()
}
@@ -963,7 +963,7 @@ func TestMaxDebitZeroDefinedRateOnlyMinutes(t *testing.T) {
}
func TestMaxDebitConsumesMinutes(t *testing.T) {
ap, _ := accountingStorage.GetActionPlans("TOPUP10_AT")
ap, _ := ratingStorage.GetActionPlans("TOPUP10_AT")
for _, at := range ap {
at.Execute()
}

View File

@@ -302,7 +302,7 @@ func (self *CdrServer) rateCDR(storedCdr *StoredCdr) error {
// Should be previously calculated and stored in DB
delay := utils.Fib()
for i := 0; i < 4; i++ {
qryCC, err = self.cdrDb.GetCallCostLog(storedCdr.CgrId, SESSION_MANAGER_SOURCE, storedCdr.MediationRunId)
qryCC, err = self.cdrDb.GetCallCostLog(storedCdr.CgrId, utils.SESSION_MANAGER_SOURCE, storedCdr.MediationRunId)
if err == nil {
break
}

View File

@@ -23,6 +23,7 @@ import (
"strings"
"github.com/cgrates/cgrates/cache2go"
"github.com/cgrates/cgrates/utils"
"github.com/cgrates/cgrates/history"
)
@@ -73,7 +74,7 @@ func (d *Destination) GetHistoryRecord() history.Record {
// Reverse search in cache to see if prefix belongs to destination id
func CachedDestHasPrefix(destId, prefix string) bool {
if cached, err := cache2go.GetCached(DESTINATION_PREFIX + prefix); err == nil {
if cached, err := cache2go.GetCached(utils.DESTINATION_PREFIX + prefix); err == nil {
_, found := cached.(map[interface{}]struct{})[destId]
return found
}
@@ -81,7 +82,7 @@ func CachedDestHasPrefix(destId, prefix string) bool {
}
func CleanStalePrefixes(destIds []string) {
prefixMap, err := cache2go.GetAllEntries(DESTINATION_PREFIX)
prefixMap, err := cache2go.GetAllEntries(utils.DESTINATION_PREFIX)
if err != nil {
return
}
@@ -92,7 +93,7 @@ func CleanStalePrefixes(destIds []string) {
if _, found := dIDs[searchedDID]; found {
if len(dIDs) == 1 {
// remove de prefix from cache
cache2go.RemKey(DESTINATION_PREFIX + prefix)
cache2go.RemKey(utils.DESTINATION_PREFIX + prefix)
} else {
// delete the destination from list and put the new list in chache
delete(dIDs, searchedDID)
@@ -101,7 +102,7 @@ func CleanStalePrefixes(destIds []string) {
}
}
if changed {
cache2go.Cache(DESTINATION_PREFIX+prefix, dIDs)
cache2go.Cache(utils.DESTINATION_PREFIX+prefix, dIDs)
}
}
}

View File

@@ -22,6 +22,7 @@ import (
"encoding/json"
"github.com/cgrates/cgrates/cache2go"
"github.com/cgrates/cgrates/utils"
"testing"
)
@@ -82,7 +83,7 @@ func TestDestinationGetExists(t *testing.T) {
func TestDestinationGetExistsCache(t *testing.T) {
ratingStorage.GetDestination("NAT")
if _, err := cache2go.GetCached(DESTINATION_PREFIX + "0256"); err != nil {
if _, err := cache2go.GetCached(utils.DESTINATION_PREFIX + "0256"); err != nil {
t.Error("Destination not cached:", err)
}
}
@@ -127,17 +128,17 @@ func TestNonCachedDestWrongPrefix(t *testing.T) {
func TestCleanStalePrefixes(t *testing.T) {
x := struct{}{}
cache2go.Cache(DESTINATION_PREFIX+"1", map[interface{}]struct{}{"D1": x, "D2": x})
cache2go.Cache(DESTINATION_PREFIX+"2", map[interface{}]struct{}{"D1": x})
cache2go.Cache(DESTINATION_PREFIX+"3", map[interface{}]struct{}{"D2": x})
cache2go.Cache(utils.DESTINATION_PREFIX+"1", map[interface{}]struct{}{"D1": x, "D2": x})
cache2go.Cache(utils.DESTINATION_PREFIX+"2", map[interface{}]struct{}{"D1": x})
cache2go.Cache(utils.DESTINATION_PREFIX+"3", map[interface{}]struct{}{"D2": x})
CleanStalePrefixes([]string{"D1"})
if r, err := cache2go.GetCached(DESTINATION_PREFIX + "1"); err != nil || len(r.(map[interface{}]struct{})) != 1 {
if r, err := cache2go.GetCached(utils.DESTINATION_PREFIX + "1"); err != nil || len(r.(map[interface{}]struct{})) != 1 {
t.Error("Error cleaning stale destination ids", r)
}
if r, err := cache2go.GetCached(DESTINATION_PREFIX + "2"); err == nil {
if r, err := cache2go.GetCached(utils.DESTINATION_PREFIX + "2"); err == nil {
t.Error("Error removing stale prefix: ", r)
}
if r, err := cache2go.GetCached(DESTINATION_PREFIX + "3"); err != nil || len(r.(map[interface{}]struct{})) != 1 {
if r, err := cache2go.GetCached(utils.DESTINATION_PREFIX + "3"); err != nil || len(r.(map[interface{}]struct{})) != 1 {
t.Error("Error performing stale cleaning: ", r)
}
}

View File

@@ -249,7 +249,7 @@ func (es LCREntriesSorter) Sort() {
func (lcra *LCRActivation) GetLCREntryForPrefix(destination string) *LCREntry {
var potentials LCREntriesSorter
for _, p := range utils.SplitPrefix(destination, MIN_PREFIX_MATCH) {
if x, err := cache2go.GetCached(DESTINATION_PREFIX + p); err == nil {
if x, err := cache2go.GetCached(utils.DESTINATION_PREFIX + p); err == nil {
destIds := x.(map[interface{}]struct{})
for idId := range destIds {

View File

@@ -47,8 +47,7 @@ func InitDataDb(cfg *config.CGRConfig) error {
return err
}
}
ratingDb.CacheRating(nil, nil, nil, nil, nil, nil)
accountDb.CacheAccounting(nil, nil, nil)
ratingDb.CacheAll()
return nil
}

View File

@@ -256,8 +256,7 @@ func init() {
log.Print("error in LoadCdrStats:", err)
}
csvr.WriteToDatabase(false, false)
ratingStorage.CacheRating(nil, nil, nil, nil, nil, nil)
accountingStorage.CacheAccounting(nil, nil, nil)
ratingStorage.CacheAll()
}
func TestLoadDestinations(t *testing.T) {

View File

@@ -99,7 +99,7 @@ func TestCreateStorTpTables(t *testing.T) {
storDb = d.(LoadStorage)
}
// Creating the table serves also as reset since there is a drop prior to create
if err := db.CreateTablesFromScript(path.Join(*dataDir, "storage", "mysql", CREATE_TARIFFPLAN_TABLES_SQL)); err != nil {
if err := db.CreateTablesFromScript(path.Join(*dataDir, "storage", "mysql", utils.CREATE_TARIFFPLAN_TABLES_SQL)); err != nil {
t.Error("Error on db creation: ", err.Error())
return // No point in going further
}
@@ -176,18 +176,18 @@ func TestImportToStorDb(t *testing.T) {
return
}
csvImporter := TPCSVImporter{
TPid: TEST_SQL,
TPid: utils.TEST_SQL,
StorDb: storDb,
DirPath: path.Join(*dataDir, "tariffplans", *tpCsvScenario),
Sep: utils.CSV_SEP,
Verbose: false,
ImportId: TEST_SQL}
ImportId: utils.TEST_SQL}
if err := csvImporter.Run(); err != nil {
t.Error("Error when importing tpdata to storDb: ", err)
}
if tpids, err := storDb.GetTpIds(); err != nil {
t.Error("Error when querying storDb for imported data: ", err)
} else if len(tpids) != 1 || tpids[0] != TEST_SQL {
} else if len(tpids) != 1 || tpids[0] != utils.TEST_SQL {
t.Errorf("Data in storDb is different than expected %v", tpids)
}
}
@@ -197,7 +197,7 @@ func TestLoadFromStorDb(t *testing.T) {
if !*testLocal {
return
}
loader := NewTpReader(ratingDbStor, accountDbStor, storDb, TEST_SQL)
loader := NewTpReader(ratingDbStor, accountDbStor, storDb, utils.TEST_SQL)
if err := loader.LoadDestinations(); err != nil {
t.Error("Failed loading destinations: ", err.Error())
}
@@ -240,9 +240,9 @@ func TestLoadIndividualProfiles(t *testing.T) {
if !*testLocal {
return
}
loader := NewTpReader(ratingDbApier, accountDbApier, storDb, TEST_SQL)
loader := NewTpReader(ratingDbApier, accountDbApier, storDb, utils.TEST_SQL)
// Load ratingPlans. This will also set destination keys
if ratingPlans, err := storDb.GetTpRatingPlans(TEST_SQL, "", nil); err != nil {
if ratingPlans, err := storDb.GetTpRatingPlans(utils.TEST_SQL, "", nil); err != nil {
t.Fatal("Could not retrieve rating plans")
} else {
rpls, err := TpRatingPlans(ratingPlans).GetRatingPlans()
@@ -258,8 +258,8 @@ func TestLoadIndividualProfiles(t *testing.T) {
}
}
// Load rating profiles
loadId := utils.CSV_LOAD + "_" + TEST_SQL
if ratingProfiles, err := storDb.GetTpRatingProfiles(&TpRatingProfile{Tpid: TEST_SQL, Loadid: loadId}); err != nil {
loadId := utils.CSV_LOAD + "_" + utils.TEST_SQL
if ratingProfiles, err := storDb.GetTpRatingProfiles(&TpRatingProfile{Tpid: utils.TEST_SQL, Loadid: loadId}); err != nil {
t.Fatal("Could not retrieve rating profiles, error: ", err.Error())
} else if len(ratingProfiles) == 0 {
t.Fatal("Could not retrieve rating profiles")
@@ -269,7 +269,7 @@ func TestLoadIndividualProfiles(t *testing.T) {
t.Fatal("Could not convert rating profiles")
}
for rpId := range rpfs {
rp, _ := utils.NewTPRatingProfileFromKeyId(TEST_SQL, loadId, rpId)
rp, _ := utils.NewTPRatingProfileFromKeyId(utils.TEST_SQL, loadId, rpId)
mrp := APItoModelRatingProfile(rp)
if err := loader.LoadRatingProfilesFiltered(&mrp[0]); err != nil {
t.Fatalf("Could not load ratingProfile with id: %s, error: %s", rpId, err.Error())
@@ -277,8 +277,8 @@ func TestLoadIndividualProfiles(t *testing.T) {
}
}
// Load derived chargers
loadId = utils.CSV_LOAD + "_" + TEST_SQL
if derivedChargers, err := storDb.GetTpDerivedChargers(&TpDerivedCharger{Tpid: TEST_SQL, Loadid: loadId}); err != nil {
loadId = utils.CSV_LOAD + "_" + utils.TEST_SQL
if derivedChargers, err := storDb.GetTpDerivedChargers(&TpDerivedCharger{Tpid: utils.TEST_SQL, Loadid: loadId}); err != nil {
t.Fatal("Could not retrieve derived chargers, error: ", err.Error())
} else if len(derivedChargers) == 0 {
t.Fatal("Could not retrieve derived chargers")
@@ -288,7 +288,7 @@ func TestLoadIndividualProfiles(t *testing.T) {
t.Fatal("Could not convert derived chargers")
}
for dcId := range dcs {
mdc := &TpDerivedCharger{Tpid: TEST_SQL, Loadid: loadId}
mdc := &TpDerivedCharger{Tpid: utils.TEST_SQL, Loadid: loadId}
mdc.SetDerivedChargersId(dcId)
if err := loader.LoadDerivedChargersFiltered(mdc, true); err != nil {
t.Fatalf("Could not load derived charger with id: %s, error: %s", dcId, err.Error())
@@ -296,7 +296,7 @@ func TestLoadIndividualProfiles(t *testing.T) {
}
}
// Load account actions
if accountActions, err := storDb.GetTpAccountActions(&TpAccountAction{Tpid: TEST_SQL, Loadid: loadId}); err != nil {
if accountActions, err := storDb.GetTpAccountActions(&TpAccountAction{Tpid: utils.TEST_SQL, Loadid: loadId}); err != nil {
t.Fatal("Could not retrieve account action profiles, error: ", err.Error())
} else if len(accountActions) == 0 {
t.Error("No account actions")
@@ -306,7 +306,7 @@ func TestLoadIndividualProfiles(t *testing.T) {
t.Fatal("Could not convert account actions")
}
for aaId := range aas {
aa, _ := utils.NewTPAccountActionsFromKeyId(TEST_SQL, loadId, aaId)
aa, _ := utils.NewTPAccountActionsFromKeyId(utils.TEST_SQL, loadId, aaId)
maa := APItoModelAccountAction(aa)
if err := loader.LoadAccountActionsFiltered(maa); err != nil {
t.Fatalf("Could not load account actions with id: %s, error: %s", aaId, err.Error())

View File

@@ -133,7 +133,7 @@ func (rp *RatingProfile) GetRatingPlansForPrefix(cd *CallDescriptor) (err error)
}
} else {
for _, p := range utils.SplitPrefix(cd.Destination, MIN_PREFIX_MATCH) {
if x, err := cache2go.GetCached(DESTINATION_PREFIX + p); err == nil {
if x, err := cache2go.GetCached(utils.DESTINATION_PREFIX + p); err == nil {
destIds := x.(map[interface{}]struct{})
for idId := range destIds {

View File

@@ -44,7 +44,7 @@ func TestResponderGetDerivedChargers(t *testing.T) {
if err := ratingStorage.SetDerivedChargers(utils.DerivedChargersKey(utils.OUT, utils.ANY, utils.ANY, utils.ANY, utils.ANY), cfgedDC); err != nil {
t.Error(err)
}
if err := ratingStorage.CacheRating([]string{}, []string{}, []string{}, []string{}, []string{}, nil); err != nil {
if err := ratingStorage.CachePrefixes(utils.DERIVEDCHARGERS_PREFIX); err != nil {
t.Error(err)
}
var dcs utils.DerivedChargers
@@ -94,8 +94,7 @@ func TestGetDerivedMaxSessionTime(t *testing.T) {
if err := ratingStorage.SetDerivedChargers(keyCharger1, charger1); err != nil {
t.Error("Error on setting DerivedChargers", err.Error())
}
ratingStorage.CacheRating(nil, nil, nil, nil, nil, nil)
accountingStorage.CacheAccounting(nil, nil, nil)
ratingStorage.CacheAll()
if rifStoredAcnt, err := accountingStorage.GetAccount(utils.ConcatenatedKey(utils.OUT, testTenant, "rif")); err != nil {
t.Error(err)
//} else if rifStoredAcnt.BalanceMap[utils.VOICE+OUTBOUND].Equal(rifsAccount.BalanceMap[utils.VOICE+OUTBOUND]) {
@@ -149,7 +148,7 @@ func TestGetSessionRuns(t *testing.T) {
if err := ratingStorage.SetDerivedChargers(keyCharger1, charger1); err != nil {
t.Error("Error on setting DerivedChargers", err.Error())
}
ratingStorage.CacheRating(nil, nil, nil, nil, nil, nil)
ratingStorage.CacheAll()
sesRuns := make([]*SessionRun, 0)
eSRuns := []*SessionRun{
&SessionRun{DerivedCharger: extra1DC,
@@ -360,12 +359,12 @@ func TestGetLCR(t *testing.T) {
t.Error(err)
}
}
if err := ratingStorage.CacheRating([]string{DESTINATION_PREFIX + dstDe.Id},
[]string{RATING_PLAN_PREFIX + rp1.Id, RATING_PLAN_PREFIX + rp2.Id},
[]string{RATING_PROFILE_PREFIX + danRpfl.Id, RATING_PROFILE_PREFIX + rifRpfl.Id},
[]string{},
[]string{LCR_PREFIX + lcrStatic.GetId(), LCR_PREFIX + lcrLowestCost.GetId()},
[]string{}); err != nil {
if err := ratingStorage.CachePrefixValues(map[string][]string{
utils.DESTINATION_PREFIX: []string{utils.DESTINATION_PREFIX + dstDe.Id},
utils.RATING_PLAN_PREFIX: []string{utils.RATING_PLAN_PREFIX + rp1.Id, utils.RATING_PLAN_PREFIX + rp2.Id},
utils.RATING_PROFILE_PREFIX: []string{utils.RATING_PROFILE_PREFIX + danRpfl.Id, utils.RATING_PROFILE_PREFIX + rifRpfl.Id},
utils.LCR_PREFIX: []string{utils.LCR_PREFIX + lcrStatic.GetId(), utils.LCR_PREFIX + lcrLowestCost.GetId()},
}); err != nil {
t.Error(err)
}
cdStatic := &CallDescriptor{

View File

@@ -32,15 +32,15 @@ func TestSharedSetGet(t *testing.T) {
},
MemberIds: []string{"1", "2", "3"},
}
err := accountingStorage.SetSharedGroup(sg)
err := ratingStorage.SetSharedGroup(sg)
if err != nil {
t.Error("Error storing Shared groudp: ", err)
}
received, err := accountingStorage.GetSharedGroup(id, true)
received, err := ratingStorage.GetSharedGroup(id, true)
if err != nil || received == nil || !reflect.DeepEqual(sg, received) {
t.Error("Error getting shared group: ", err, received)
}
received, err = accountingStorage.GetSharedGroup(id, false)
received, err = ratingStorage.GetSharedGroup(id, false)
if err != nil || received == nil || !reflect.DeepEqual(sg, received) {
t.Error("Error getting cached shared group: ", err, received)
}

View File

@@ -29,38 +29,6 @@ import (
"gopkg.in/mgo.v2/bson"
)
const (
ACTION_TIMING_PREFIX = "apl_"
RATING_PLAN_PREFIX = "rpl_"
RATING_PROFILE_PREFIX = "rpf_"
RP_ALIAS_PREFIX = "ral_"
ACC_ALIAS_PREFIX = "aal_"
ACTION_PREFIX = "act_"
SHARED_GROUP_PREFIX = "shg_"
ACCOUNT_PREFIX = "ubl_"
DESTINATION_PREFIX = "dst_"
LCR_PREFIX = "lcr_"
DERIVEDCHARGERS_PREFIX = "dcs_"
CDR_STATS_PREFIX = "cst_"
TEMP_DESTINATION_PREFIX = "tmp_"
LOG_CALL_COST_PREFIX = "cco_"
LOG_ACTION_TIMMING_PREFIX = "ltm_"
LOG_ACTION_TRIGGER_PREFIX = "ltr_"
LOG_ERR = "ler_"
LOG_CDR = "cdr_"
LOG_MEDIATED_CDR = "mcd_"
// sources
SESSION_MANAGER_SOURCE = "SMR"
MEDIATOR_SOURCE = "MED"
SCHED_SOURCE = "SCH"
RATER_SOURCE = "RAT"
CREATE_CDRS_TABLES_SQL = "create_cdrs_tables.sql"
CREATE_TARIFFPLAN_TABLES_SQL = "create_tariffplan_tables.sql"
TEST_SQL = "TEST_SQL"
DESTINATIONS_LOAD_THRESHOLD = 0.1
)
type Storage interface {
Close()
Flush(string) error
@@ -70,7 +38,10 @@ type Storage interface {
// Interface for storage providers.
type RatingStorage interface {
Storage
CacheRating([]string, []string, []string, []string, []string, []string) error
CacheAll() error
CachePrefixes(...string) error
CachePrefixValues(map[string][]string) error
Cache([]string, []string, []string, []string, []string, []string, []string, []string, []string) error
HasData(string, string) (bool, error)
GetRatingPlan(string, bool) (*RatingPlan, error)
SetRatingPlan(*RatingPlan) error
@@ -89,25 +60,23 @@ type RatingStorage interface {
GetAllCdrStats() ([]*CdrStats, error)
GetDerivedChargers(string, bool) (utils.DerivedChargers, error)
SetDerivedChargers(string, utils.DerivedChargers) error
}
type AccountingStorage interface {
Storage
HasData(string, string) (bool, error)
CacheAccounting([]string, []string, []string) error
GetActions(string, bool) (Actions, error)
SetActions(string, Actions) error
GetSharedGroup(string, bool) (*SharedGroup, error)
SetSharedGroup(*SharedGroup) error
GetAccount(string) (*Account, error)
SetAccount(*Account) error
GetActionPlans(string) (ActionPlans, error)
SetActionPlans(string, ActionPlans) error
GetAllActionPlans() (map[string]ActionPlans, error)
GetAccAlias(string, bool) (string, error)
SetAccAlias(string, string) error
RemoveAccAliases([]*TenantAccount) error
GetAccountAliases(string, string, bool) ([]string, error)
GetActionPlans(string) (ActionPlans, error)
SetActionPlans(string, ActionPlans) error
GetAllActionPlans() (map[string]ActionPlans, error)
}
type AccountingStorage interface {
Storage
GetAccount(string) (*Account, error)
SetAccount(*Account) error
}
type CdrStorage interface {

View File

@@ -62,104 +62,144 @@ func (ms *MapStorage) GetKeysForPrefix(prefix string) ([]string, error) {
return keysForPrefix, nil
}
func (ms *MapStorage) CacheRating(dKeys, rpKeys, rpfKeys, alsKeys, lcrKeys, dcsKeys []string) error {
func (ms *MapStorage) CacheAll() error {
return ms.Cache(nil, nil, nil, nil, nil, nil, nil, nil, nil)
}
func (ms *MapStorage) CachePrefixes(prefixes ...string) error {
pm := map[string][]string{
utils.DESTINATION_PREFIX: []string{},
utils.RATING_PLAN_PREFIX: []string{},
utils.RATING_PROFILE_PREFIX: []string{},
utils.RP_ALIAS_PREFIX: []string{},
utils.LCR_PREFIX: []string{},
utils.DERIVEDCHARGERS_PREFIX: []string{},
utils.ACTION_PREFIX: []string{},
utils.SHARED_GROUP_PREFIX: []string{},
utils.ACC_ALIAS_PREFIX: []string{},
}
for _, prefix := range prefixes {
if _, found := pm[prefix]; !found {
return utils.ErrNotFound
}
pm[prefix] = nil
}
return ms.Cache(pm[utils.DESTINATION_PREFIX], pm[utils.RATING_PLAN_PREFIX], pm[utils.RATING_PROFILE_PREFIX], pm[utils.RP_ALIAS_PREFIX], pm[utils.LCR_PREFIX], pm[utils.DERIVEDCHARGERS_PREFIX], pm[utils.ACTION_PREFIX], pm[utils.SHARED_GROUP_PREFIX], pm[utils.ACC_ALIAS_PREFIX])
}
func (ms *MapStorage) CachePrefixValues(prefixes map[string][]string) error {
pm := map[string][]string{
utils.DESTINATION_PREFIX: []string{},
utils.RATING_PLAN_PREFIX: []string{},
utils.RATING_PROFILE_PREFIX: []string{},
utils.RP_ALIAS_PREFIX: []string{},
utils.LCR_PREFIX: []string{},
utils.DERIVEDCHARGERS_PREFIX: []string{},
utils.ACTION_PREFIX: []string{},
utils.SHARED_GROUP_PREFIX: []string{},
utils.ACC_ALIAS_PREFIX: []string{},
}
for prefix, ids := range prefixes {
if _, found := pm[prefix]; !found {
return utils.ErrNotFound
}
pm[prefix] = ids
}
return ms.Cache(pm[utils.DESTINATION_PREFIX], pm[utils.RATING_PLAN_PREFIX], pm[utils.RATING_PROFILE_PREFIX], pm[utils.RP_ALIAS_PREFIX], pm[utils.LCR_PREFIX], pm[utils.DERIVEDCHARGERS_PREFIX], pm[utils.ACTION_PREFIX], pm[utils.SHARED_GROUP_PREFIX], pm[utils.ACC_ALIAS_PREFIX])
}
func (ms *MapStorage) Cache(dKeys, rpKeys, rpfKeys, plsKeys, lcrKeys, dcsKeys, actKeys, shgKeys, alsKeys []string) error {
cache2go.BeginTransaction()
if dKeys == nil || (float64(cache2go.CountEntries(DESTINATION_PREFIX))*DESTINATIONS_LOAD_THRESHOLD < float64(len(dKeys))) {
cache2go.RemPrefixKey(DESTINATION_PREFIX)
if dKeys == nil || (float64(cache2go.CountEntries(utils.DESTINATION_PREFIX))*utils.DESTINATIONS_LOAD_THRESHOLD < float64(len(dKeys))) {
cache2go.RemPrefixKey(utils.DESTINATION_PREFIX)
} else {
CleanStalePrefixes(dKeys)
}
if rpKeys == nil {
cache2go.RemPrefixKey(RATING_PLAN_PREFIX)
cache2go.RemPrefixKey(utils.RATING_PLAN_PREFIX)
}
if rpfKeys == nil {
cache2go.RemPrefixKey(RATING_PROFILE_PREFIX)
cache2go.RemPrefixKey(utils.RATING_PROFILE_PREFIX)
}
if alsKeys == nil {
cache2go.RemPrefixKey(RP_ALIAS_PREFIX)
if plsKeys == nil {
cache2go.RemPrefixKey(utils.RP_ALIAS_PREFIX)
}
if lcrKeys == nil {
cache2go.RemPrefixKey(LCR_PREFIX)
cache2go.RemPrefixKey(utils.LCR_PREFIX)
}
if dcsKeys == nil {
cache2go.RemPrefixKey(DERIVEDCHARGERS_PREFIX)
cache2go.RemPrefixKey(utils.DERIVEDCHARGERS_PREFIX)
}
for k, _ := range ms.dict {
if strings.HasPrefix(k, DESTINATION_PREFIX) {
if _, err := ms.GetDestination(k[len(DESTINATION_PREFIX):]); err != nil {
cache2go.RollbackTransaction()
return err
}
}
if strings.HasPrefix(k, RATING_PLAN_PREFIX) {
cache2go.RemKey(k)
if _, err := ms.GetRatingPlan(k[len(RATING_PLAN_PREFIX):], true); err != nil {
cache2go.RollbackTransaction()
return err
}
}
if strings.HasPrefix(k, RATING_PROFILE_PREFIX) {
cache2go.RemKey(k)
if _, err := ms.GetRatingProfile(k[len(RATING_PROFILE_PREFIX):], true); err != nil {
cache2go.RollbackTransaction()
return err
}
}
if strings.HasPrefix(k, RP_ALIAS_PREFIX) {
cache2go.RemKey(k)
if _, err := ms.GetRpAlias(k[len(RP_ALIAS_PREFIX):], true); err != nil {
cache2go.RollbackTransaction()
return err
}
}
if strings.HasPrefix(k, LCR_PREFIX) {
cache2go.RemKey(k)
if _, err := ms.GetLCR(k[len(LCR_PREFIX):], true); err != nil {
cache2go.RollbackTransaction()
return err
}
}
if strings.HasPrefix(k, DERIVEDCHARGERS_PREFIX) {
cache2go.RemKey(k)
if _, err := ms.GetDerivedChargers(k[len(DERIVEDCHARGERS_PREFIX):], true); err != nil {
cache2go.RollbackTransaction()
return err
}
}
}
cache2go.CommitTransaction()
return nil
}
func (ms *MapStorage) CacheAccounting(actKeys, shgKeys, alsKeys []string) error {
cache2go.BeginTransaction()
if actKeys == nil {
cache2go.RemPrefixKey(ACTION_PREFIX) // Forced until we can fine tune it
cache2go.RemPrefixKey(utils.ACTION_PREFIX) // Forced until we can fine tune it
}
if shgKeys == nil {
cache2go.RemPrefixKey(SHARED_GROUP_PREFIX) // Forced until we can fine tune it
cache2go.RemPrefixKey(utils.SHARED_GROUP_PREFIX) // Forced until we can fine tune it
}
if alsKeys == nil {
cache2go.RemPrefixKey(ACC_ALIAS_PREFIX)
cache2go.RemPrefixKey(utils.ACC_ALIAS_PREFIX)
}
for k, _ := range ms.dict {
if strings.HasPrefix(k, ACTION_PREFIX) {
cache2go.RemKey(k)
if _, err := ms.GetActions(k[len(ACTION_PREFIX):], true); err != nil {
if strings.HasPrefix(k, utils.DESTINATION_PREFIX) {
if _, err := ms.GetDestination(k[len(utils.DESTINATION_PREFIX):]); err != nil {
cache2go.RollbackTransaction()
return err
}
}
if strings.HasPrefix(k, SHARED_GROUP_PREFIX) {
if strings.HasPrefix(k, utils.RATING_PLAN_PREFIX) {
cache2go.RemKey(k)
if _, err := ms.GetSharedGroup(k[len(SHARED_GROUP_PREFIX):], true); err != nil {
if _, err := ms.GetRatingPlan(k[len(utils.RATING_PLAN_PREFIX):], true); err != nil {
cache2go.RollbackTransaction()
return err
}
}
if strings.HasPrefix(k, ACC_ALIAS_PREFIX) {
if strings.HasPrefix(k, utils.RATING_PROFILE_PREFIX) {
cache2go.RemKey(k)
if _, err := ms.GetAccAlias(k[len(ACC_ALIAS_PREFIX):], true); err != nil {
if _, err := ms.GetRatingProfile(k[len(utils.RATING_PROFILE_PREFIX):], true); err != nil {
cache2go.RollbackTransaction()
return err
}
}
if strings.HasPrefix(k, utils.RP_ALIAS_PREFIX) {
cache2go.RemKey(k)
if _, err := ms.GetRpAlias(k[len(utils.RP_ALIAS_PREFIX):], true); err != nil {
cache2go.RollbackTransaction()
return err
}
}
if strings.HasPrefix(k, utils.LCR_PREFIX) {
cache2go.RemKey(k)
if _, err := ms.GetLCR(k[len(utils.LCR_PREFIX):], true); err != nil {
cache2go.RollbackTransaction()
return err
}
}
if strings.HasPrefix(k, utils.DERIVEDCHARGERS_PREFIX) {
cache2go.RemKey(k)
if _, err := ms.GetDerivedChargers(k[len(utils.DERIVEDCHARGERS_PREFIX):], true); err != nil {
cache2go.RollbackTransaction()
return err
}
}
}
for k, _ := range ms.dict {
if strings.HasPrefix(k, utils.ACTION_PREFIX) {
cache2go.RemKey(k)
if _, err := ms.GetActions(k[len(utils.ACTION_PREFIX):], true); err != nil {
cache2go.RollbackTransaction()
return err
}
}
if strings.HasPrefix(k, utils.SHARED_GROUP_PREFIX) {
cache2go.RemKey(k)
if _, err := ms.GetSharedGroup(k[len(utils.SHARED_GROUP_PREFIX):], true); err != nil {
cache2go.RollbackTransaction()
return err
}
}
if strings.HasPrefix(k, utils.ACC_ALIAS_PREFIX) {
cache2go.RemKey(k)
if _, err := ms.GetAccAlias(k[len(utils.ACC_ALIAS_PREFIX):], true); err != nil {
cache2go.RollbackTransaction()
return err
}
@@ -172,18 +212,18 @@ func (ms *MapStorage) CacheAccounting(actKeys, shgKeys, alsKeys []string) error
// Used to check if specific subject is stored using prefix key attached to entity
func (ms *MapStorage) HasData(categ, subject string) (bool, error) {
switch categ {
case DESTINATION_PREFIX:
_, exists := ms.dict[DESTINATION_PREFIX+subject]
case utils.DESTINATION_PREFIX:
_, exists := ms.dict[utils.DESTINATION_PREFIX+subject]
return exists, nil
case RATING_PLAN_PREFIX:
_, exists := ms.dict[RATING_PLAN_PREFIX+subject]
case utils.RATING_PLAN_PREFIX:
_, exists := ms.dict[utils.RATING_PLAN_PREFIX+subject]
return exists, nil
}
return false, errors.New("Unsupported category")
}
func (ms *MapStorage) GetRatingPlan(key string, skipCache bool) (rp *RatingPlan, err error) {
key = RATING_PLAN_PREFIX + key
key = utils.RATING_PLAN_PREFIX + key
if !skipCache {
if x, err := cache2go.GetCached(key); err == nil {
return x.(*RatingPlan), nil
@@ -217,7 +257,7 @@ func (ms *MapStorage) SetRatingPlan(rp *RatingPlan) (err error) {
w := zlib.NewWriter(&b)
w.Write(result)
w.Close()
ms.dict[RATING_PLAN_PREFIX+rp.Id] = b.Bytes()
ms.dict[utils.RATING_PLAN_PREFIX+rp.Id] = b.Bytes()
response := 0
if historyScribe != nil {
go historyScribe.Record(rp.GetHistoryRecord(), &response)
@@ -227,7 +267,7 @@ func (ms *MapStorage) SetRatingPlan(rp *RatingPlan) (err error) {
}
func (ms *MapStorage) GetRatingProfile(key string, skipCache bool) (rpf *RatingProfile, err error) {
key = RATING_PROFILE_PREFIX + key
key = utils.RATING_PROFILE_PREFIX + key
if !skipCache {
if x, err := cache2go.GetCached(key); err == nil {
return x.(*RatingProfile), nil
@@ -248,7 +288,7 @@ func (ms *MapStorage) GetRatingProfile(key string, skipCache bool) (rpf *RatingP
func (ms *MapStorage) SetRatingProfile(rpf *RatingProfile) (err error) {
result, err := ms.ms.Marshal(rpf)
ms.dict[RATING_PROFILE_PREFIX+rpf.Id] = result
ms.dict[utils.RATING_PROFILE_PREFIX+rpf.Id] = result
response := 0
if historyScribe != nil {
go historyScribe.Record(rpf.GetHistoryRecord(), &response)
@@ -258,7 +298,7 @@ func (ms *MapStorage) SetRatingProfile(rpf *RatingProfile) (err error) {
}
func (ms *MapStorage) GetLCR(key string, skipCache bool) (lcr *LCR, err error) {
key = LCR_PREFIX + key
key = utils.LCR_PREFIX + key
if !skipCache {
if x, err := cache2go.GetCached(key); err == nil {
return x.(*LCR), nil
@@ -277,13 +317,13 @@ func (ms *MapStorage) GetLCR(key string, skipCache bool) (lcr *LCR, err error) {
func (ms *MapStorage) SetLCR(lcr *LCR) (err error) {
result, err := ms.ms.Marshal(lcr)
ms.dict[LCR_PREFIX+lcr.GetId()] = result
ms.dict[utils.LCR_PREFIX+lcr.GetId()] = result
//cache2go.Cache(LCR_PREFIX+key, lcr)
return
}
func (ms *MapStorage) GetRpAlias(key string, skipCache bool) (alias string, err error) {
key = RP_ALIAS_PREFIX + key
key = utils.RP_ALIAS_PREFIX + key
if !skipCache {
if x, err := cache2go.GetCached(key); err == nil {
return x.(string), nil
@@ -301,7 +341,7 @@ func (ms *MapStorage) GetRpAlias(key string, skipCache bool) (alias string, err
}
func (ms *MapStorage) SetRpAlias(key, alias string) (err error) {
ms.dict[RP_ALIAS_PREFIX+key] = []byte(alias)
ms.dict[utils.RP_ALIAS_PREFIX+key] = []byte(alias)
//cache2go.Cache(ALIAS_PREFIX+key, alias)
return
}
@@ -309,9 +349,9 @@ func (ms *MapStorage) SetRpAlias(key, alias string) (err error) {
func (ms *MapStorage) RemoveRpAliases(tenantRtSubjects []*TenantRatingSubject) (err error) {
for key, _ := range ms.dict {
for _, tntRtSubj := range tenantRtSubjects {
tenantPrfx := RP_ALIAS_PREFIX + tntRtSubj.Tenant + utils.CONCATENATED_KEY_SEP
if strings.HasPrefix(key, RP_ALIAS_PREFIX) {
alsSubj, err := ms.GetRpAlias(key[len(RP_ALIAS_PREFIX):], true)
tenantPrfx := utils.RP_ALIAS_PREFIX + tntRtSubj.Tenant + utils.CONCATENATED_KEY_SEP
if strings.HasPrefix(key, utils.RP_ALIAS_PREFIX) {
alsSubj, err := ms.GetRpAlias(key[len(utils.RP_ALIAS_PREFIX):], true)
if err != nil {
return err
}
@@ -326,13 +366,13 @@ func (ms *MapStorage) RemoveRpAliases(tenantRtSubjects []*TenantRatingSubject) (
}
func (ms *MapStorage) GetRPAliases(tenant, subject string, skipCache bool) (aliases []string, err error) {
tenantPrfx := RP_ALIAS_PREFIX + tenant + utils.CONCATENATED_KEY_SEP
tenantPrfx := utils.RP_ALIAS_PREFIX + tenant + utils.CONCATENATED_KEY_SEP
var alsKeys []string
if !skipCache {
alsKeys = cache2go.GetEntriesKeys(tenantPrfx)
}
for _, key := range alsKeys {
if alsSubj, err := ms.GetRpAlias(key[len(RP_ALIAS_PREFIX):], skipCache); err != nil {
if alsSubj, err := ms.GetRpAlias(key[len(utils.RP_ALIAS_PREFIX):], skipCache); err != nil {
return nil, err
} else if alsSubj == subject {
alsFromKey := key[len(tenantPrfx):] // take out the alias out of key+tenant
@@ -341,7 +381,7 @@ func (ms *MapStorage) GetRPAliases(tenant, subject string, skipCache bool) (alia
}
if len(alsKeys) == 0 {
for key, value := range ms.dict {
if strings.HasPrefix(key, RP_ALIAS_PREFIX) && len(key) >= len(tenantPrfx) && key[:len(tenantPrfx)] == tenantPrfx && subject == string(value) {
if strings.HasPrefix(key, utils.RP_ALIAS_PREFIX) && len(key) >= len(tenantPrfx) && key[:len(tenantPrfx)] == tenantPrfx && subject == string(value) {
aliases = append(aliases, key[len(tenantPrfx):])
}
}
@@ -350,7 +390,7 @@ func (ms *MapStorage) GetRPAliases(tenant, subject string, skipCache bool) (alia
}
func (ms *MapStorage) GetAccAlias(key string, skipCache bool) (alias string, err error) {
key = ACC_ALIAS_PREFIX + key
key = utils.ACC_ALIAS_PREFIX + key
if !skipCache {
if x, err := cache2go.GetCached(key); err == nil {
return x.(string), nil
@@ -368,7 +408,7 @@ func (ms *MapStorage) GetAccAlias(key string, skipCache bool) (alias string, err
}
func (ms *MapStorage) SetAccAlias(key, alias string) (err error) {
ms.dict[ACC_ALIAS_PREFIX+key] = []byte(alias)
ms.dict[utils.ACC_ALIAS_PREFIX+key] = []byte(alias)
//cache2go.Cache(ALIAS_PREFIX+key, alias)
return
}
@@ -376,8 +416,8 @@ func (ms *MapStorage) SetAccAlias(key, alias string) (err error) {
func (ms *MapStorage) RemoveAccAliases(tenantAccounts []*TenantAccount) (err error) {
for key, value := range ms.dict {
for _, tntAcnt := range tenantAccounts {
tenantPrfx := ACC_ALIAS_PREFIX + tntAcnt.Tenant + utils.CONCATENATED_KEY_SEP
if strings.HasPrefix(key, ACC_ALIAS_PREFIX) && len(key) >= len(tenantPrfx) && key[:len(tenantPrfx)] == tenantPrfx && tntAcnt.Account == string(value) {
tenantPrfx := utils.ACC_ALIAS_PREFIX + tntAcnt.Tenant + utils.CONCATENATED_KEY_SEP
if strings.HasPrefix(key, utils.ACC_ALIAS_PREFIX) && len(key) >= len(tenantPrfx) && key[:len(tenantPrfx)] == tenantPrfx && tntAcnt.Account == string(value) {
delete(ms.dict, key)
}
}
@@ -387,8 +427,8 @@ func (ms *MapStorage) RemoveAccAliases(tenantAccounts []*TenantAccount) (err err
func (ms *MapStorage) GetAccountAliases(tenant, account string, skipCache bool) (aliases []string, err error) {
for key, value := range ms.dict {
tenantPrfx := ACC_ALIAS_PREFIX + tenant + utils.CONCATENATED_KEY_SEP
if strings.HasPrefix(key, ACC_ALIAS_PREFIX) && len(key) >= len(tenantPrfx) && key[:len(tenantPrfx)] == tenantPrfx && account == string(value) {
tenantPrfx := utils.ACC_ALIAS_PREFIX + tenant + utils.CONCATENATED_KEY_SEP
if strings.HasPrefix(key, utils.ACC_ALIAS_PREFIX) && len(key) >= len(tenantPrfx) && key[:len(tenantPrfx)] == tenantPrfx && account == string(value) {
aliases = append(aliases, key[len(tenantPrfx):])
}
}
@@ -396,7 +436,7 @@ func (ms *MapStorage) GetAccountAliases(tenant, account string, skipCache bool)
}
func (ms *MapStorage) GetDestination(key string) (dest *Destination, err error) {
key = DESTINATION_PREFIX + key
key = utils.DESTINATION_PREFIX + key
if values, ok := ms.dict[key]; ok {
b := bytes.NewBuffer(values)
r, err := zlib.NewReader(b)
@@ -412,7 +452,7 @@ func (ms *MapStorage) GetDestination(key string) (dest *Destination, err error)
err = ms.ms.Unmarshal(out, dest)
// create optimized structure
for _, p := range dest.Prefixes {
cache2go.CachePush(DESTINATION_PREFIX+p, dest.Id)
cache2go.CachePush(utils.DESTINATION_PREFIX+p, dest.Id)
}
} else {
return nil, utils.ErrNotFound
@@ -426,7 +466,7 @@ func (ms *MapStorage) SetDestination(dest *Destination) (err error) {
w := zlib.NewWriter(&b)
w.Write(result)
w.Close()
ms.dict[DESTINATION_PREFIX+dest.Id] = b.Bytes()
ms.dict[utils.DESTINATION_PREFIX+dest.Id] = b.Bytes()
response := 0
if historyScribe != nil {
go historyScribe.Record(dest.GetHistoryRecord(), &response)
@@ -436,7 +476,7 @@ func (ms *MapStorage) SetDestination(dest *Destination) (err error) {
}
func (ms *MapStorage) GetActions(key string, skipCache bool) (as Actions, err error) {
key = ACTION_PREFIX + key
key = utils.ACTION_PREFIX + key
if !skipCache {
if x, err := cache2go.GetCached(key); err == nil {
return x.(Actions), nil
@@ -455,13 +495,13 @@ func (ms *MapStorage) GetActions(key string, skipCache bool) (as Actions, err er
func (ms *MapStorage) SetActions(key string, as Actions) (err error) {
result, err := ms.ms.Marshal(&as)
ms.dict[ACTION_PREFIX+key] = result
ms.dict[utils.ACTION_PREFIX+key] = result
//cache2go.Cache(ACTION_PREFIX+key, as)
return
}
func (ms *MapStorage) GetSharedGroup(key string, skipCache bool) (sg *SharedGroup, err error) {
key = SHARED_GROUP_PREFIX + key
key = utils.SHARED_GROUP_PREFIX + key
if !skipCache {
if x, err := cache2go.GetCached(key); err == nil {
return x.(*SharedGroup), nil
@@ -480,13 +520,13 @@ func (ms *MapStorage) GetSharedGroup(key string, skipCache bool) (sg *SharedGrou
func (ms *MapStorage) SetSharedGroup(sg *SharedGroup) (err error) {
result, err := ms.ms.Marshal(sg)
ms.dict[SHARED_GROUP_PREFIX+sg.Id] = result
ms.dict[utils.SHARED_GROUP_PREFIX+sg.Id] = result
//cache2go.Cache(SHARED_GROUP_PREFIX+key, sg)
return
}
func (ms *MapStorage) GetAccount(key string) (ub *Account, err error) {
if values, ok := ms.dict[ACCOUNT_PREFIX+key]; ok {
if values, ok := ms.dict[utils.ACCOUNT_PREFIX+key]; ok {
ub = &Account{Id: key}
err = ms.ms.Unmarshal(values, ub)
} else {
@@ -509,12 +549,12 @@ func (ms *MapStorage) SetAccount(ub *Account) (err error) {
}
}
result, err := ms.ms.Marshal(ub)
ms.dict[ACCOUNT_PREFIX+ub.Id] = result
ms.dict[utils.ACCOUNT_PREFIX+ub.Id] = result
return
}
func (ms *MapStorage) GetActionPlans(key string) (ats ActionPlans, err error) {
if values, ok := ms.dict[ACTION_TIMING_PREFIX+key]; ok {
if values, ok := ms.dict[utils.ACTION_TIMING_PREFIX+key]; ok {
err = ms.ms.Unmarshal(values, &ats)
} else {
return nil, utils.ErrNotFound
@@ -525,30 +565,30 @@ func (ms *MapStorage) GetActionPlans(key string) (ats ActionPlans, err error) {
func (ms *MapStorage) SetActionPlans(key string, ats ActionPlans) (err error) {
if len(ats) == 0 {
// delete the key
delete(ms.dict, ACTION_TIMING_PREFIX+key)
delete(ms.dict, utils.ACTION_TIMING_PREFIX+key)
return
}
result, err := ms.ms.Marshal(&ats)
ms.dict[ACTION_TIMING_PREFIX+key] = result
ms.dict[utils.ACTION_TIMING_PREFIX+key] = result
return
}
func (ms *MapStorage) GetAllActionPlans() (ats map[string]ActionPlans, err error) {
ats = make(map[string]ActionPlans)
for key, value := range ms.dict {
if !strings.HasPrefix(key, ACTION_TIMING_PREFIX) {
if !strings.HasPrefix(key, utils.ACTION_TIMING_PREFIX) {
continue
}
var tempAts ActionPlans
err = ms.ms.Unmarshal(value, &tempAts)
ats[key[len(ACTION_TIMING_PREFIX):]] = tempAts
ats[key[len(utils.ACTION_TIMING_PREFIX):]] = tempAts
}
return
}
func (ms *MapStorage) GetDerivedChargers(key string, skipCache bool) (dcs utils.DerivedChargers, err error) {
key = DERIVEDCHARGERS_PREFIX + key
key = utils.DERIVEDCHARGERS_PREFIX + key
if !skipCache {
if x, err := cache2go.GetCached(key); err == nil {
return x.(utils.DerivedChargers), nil
@@ -567,18 +607,18 @@ func (ms *MapStorage) GetDerivedChargers(key string, skipCache bool) (dcs utils.
func (ms *MapStorage) SetDerivedChargers(key string, dcs utils.DerivedChargers) error {
result, err := ms.ms.Marshal(dcs)
ms.dict[DERIVEDCHARGERS_PREFIX+key] = result
ms.dict[utils.DERIVEDCHARGERS_PREFIX+key] = result
return err
}
func (ms *MapStorage) SetCdrStats(cs *CdrStats) error {
result, err := ms.ms.Marshal(cs)
ms.dict[CDR_STATS_PREFIX+cs.Id] = result
ms.dict[utils.CDR_STATS_PREFIX+cs.Id] = result
return err
}
func (ms *MapStorage) GetCdrStats(key string) (cs *CdrStats, err error) {
if values, ok := ms.dict[CDR_STATS_PREFIX+key]; ok {
if values, ok := ms.dict[utils.CDR_STATS_PREFIX+key]; ok {
err = ms.ms.Unmarshal(values, &cs)
} else {
return nil, utils.ErrNotFound
@@ -588,7 +628,7 @@ func (ms *MapStorage) GetCdrStats(key string) (cs *CdrStats, err error) {
func (ms *MapStorage) GetAllCdrStats() (css []*CdrStats, err error) {
for key, value := range ms.dict {
if !strings.HasPrefix(key, CDR_STATS_PREFIX) {
if !strings.HasPrefix(key, utils.CDR_STATS_PREFIX) {
continue
}
cs := &CdrStats{}
@@ -600,12 +640,12 @@ func (ms *MapStorage) GetAllCdrStats() (css []*CdrStats, err error) {
func (ms *MapStorage) LogCallCost(cgrid, source, runid string, cc *CallCost) error {
result, err := ms.ms.Marshal(cc)
ms.dict[LOG_CALL_COST_PREFIX+source+runid+"_"+cgrid] = result
ms.dict[utils.LOG_CALL_COST_PREFIX+source+runid+"_"+cgrid] = result
return err
}
func (ms *MapStorage) GetCallCostLog(cgrid, source, runid string) (cc *CallCost, err error) {
if values, ok := ms.dict[LOG_CALL_COST_PREFIX+source+runid+"_"+cgrid]; ok {
if values, ok := ms.dict[utils.LOG_CALL_COST_PREFIX+source+runid+"_"+cgrid]; ok {
err = ms.ms.Unmarshal(values, &cc)
} else {
return nil, utils.ErrNotFound
@@ -622,7 +662,7 @@ func (ms *MapStorage) LogActionTrigger(ubId, source string, at *ActionTrigger, a
if err != nil {
return
}
ms.dict[LOG_ACTION_TRIGGER_PREFIX+source+"_"+time.Now().Format(time.RFC3339Nano)] = []byte(fmt.Sprintf("%s*%s*%s", ubId, string(mat), string(mas)))
ms.dict[utils.LOG_ACTION_TRIGGER_PREFIX+source+"_"+time.Now().Format(time.RFC3339Nano)] = []byte(fmt.Sprintf("%s*%s*%s", ubId, string(mat), string(mas)))
return
}
@@ -635,11 +675,11 @@ func (ms *MapStorage) LogActionPlan(source string, at *ActionPlan, as Actions) (
if err != nil {
return
}
ms.dict[LOG_ACTION_TIMMING_PREFIX+source+"_"+time.Now().Format(time.RFC3339Nano)] = []byte(fmt.Sprintf("%s*%s", string(mat), string(mas)))
ms.dict[utils.LOG_ACTION_TIMMING_PREFIX+source+"_"+time.Now().Format(time.RFC3339Nano)] = []byte(fmt.Sprintf("%s*%s", string(mat), string(mas)))
return
}
func (ms *MapStorage) LogError(uuid, source, runid, errstr string) (err error) {
ms.dict[LOG_ERR+source+runid+"_"+uuid] = []byte(errstr)
ms.dict[utils.LOG_ERR+source+runid+"_"+uuid] = []byte(errstr)
return nil
}

View File

@@ -49,7 +49,7 @@ type MySQLStorage struct {
}
func (self *MySQLStorage) Flush(scriptsPath string) (err error) {
for _, scriptName := range []string{CREATE_CDRS_TABLES_SQL, CREATE_TARIFFPLAN_TABLES_SQL} {
for _, scriptName := range []string{utils.CREATE_CDRS_TABLES_SQL, utils.CREATE_TARIFFPLAN_TABLES_SQL} {
if err := self.CreateTablesFromScript(path.Join(scriptsPath, scriptName)); err != nil {
return err
}

View File

@@ -43,7 +43,7 @@ func TestMySQLCreateTables(t *testing.T) {
} else {
mysqlDb = d.(*MySQLStorage)
}
for _, scriptName := range []string{CREATE_CDRS_TABLES_SQL, CREATE_TARIFFPLAN_TABLES_SQL} {
for _, scriptName := range []string{utils.CREATE_CDRS_TABLES_SQL, utils.CREATE_TARIFFPLAN_TABLES_SQL} {
if err := mysqlDb.CreateTablesFromScript(path.Join(*dataDir, "storage", utils.MYSQL, scriptName)); err != nil {
t.Error("Error on mysqlDb creation: ", err.Error())
return // No point in going further
@@ -60,11 +60,11 @@ func TestMySQLSetGetTPTiming(t *testing.T) {
if !*testLocal {
return
}
tm := TpTiming{Tpid: TEST_SQL, Tag: "ALWAYS", Time: "00:00:00"}
tm := TpTiming{Tpid: utils.TEST_SQL, Tag: "ALWAYS", Time: "00:00:00"}
if err := mysqlDb.SetTpTimings([]TpTiming{tm}); err != nil {
t.Error(err.Error())
}
if tmgs, err := mysqlDb.GetTpTimings(TEST_SQL, tm.Tag); err != nil {
if tmgs, err := mysqlDb.GetTpTimings(utils.TEST_SQL, tm.Tag); err != nil {
t.Error(err.Error())
} else if !modelEqual(tm, tmgs[0]) {
t.Errorf("Expecting: %+v, received: %+v", tm, tmgs[0])
@@ -74,7 +74,7 @@ func TestMySQLSetGetTPTiming(t *testing.T) {
if err := mysqlDb.SetTpTimings([]TpTiming{tm}); err != nil {
t.Error(err.Error())
}
if tmgs, err := mysqlDb.GetTpTimings(TEST_SQL, tm.Tag); err != nil {
if tmgs, err := mysqlDb.GetTpTimings(utils.TEST_SQL, tm.Tag); err != nil {
t.Error(err.Error())
} else if !modelEqual(tm, tmgs[0]) {
t.Errorf("Expecting: %+v, received: %+v", tm, tmgs[0])
@@ -86,20 +86,20 @@ func TestMySQLSetGetTPDestination(t *testing.T) {
return
}
dst := []TpDestination{
TpDestination{Tpid: TEST_SQL, Tag: TEST_SQL, Prefix: "+49"},
TpDestination{Tpid: TEST_SQL, Tag: TEST_SQL, Prefix: "+49151"},
TpDestination{Tpid: TEST_SQL, Tag: TEST_SQL, Prefix: "+49176"},
TpDestination{Tpid: utils.TEST_SQL, Tag: utils.TEST_SQL, Prefix: "+49"},
TpDestination{Tpid: utils.TEST_SQL, Tag: utils.TEST_SQL, Prefix: "+49151"},
TpDestination{Tpid: utils.TEST_SQL, Tag: utils.TEST_SQL, Prefix: "+49176"},
}
if err := mysqlDb.SetTpDestinations(dst); err != nil {
t.Error(err.Error())
}
storData, err := mysqlDb.GetTpDestinations(TEST_SQL, TEST_SQL)
storData, err := mysqlDb.GetTpDestinations(utils.TEST_SQL, utils.TEST_SQL)
dsts, err := TpDestinations(storData).GetDestinations()
expected := &Destination{Id: TEST_SQL, Prefixes: []string{"+49", "+49151", "+49176"}}
expected := &Destination{Id: utils.TEST_SQL, Prefixes: []string{"+49", "+49151", "+49176"}}
if err != nil {
t.Error(err.Error())
} else if !modelEqual(*expected, *dsts[TEST_SQL]) {
t.Errorf("Expecting: %+v, received: %+v", expected, dsts[TEST_SQL])
} else if !modelEqual(*expected, *dsts[utils.TEST_SQL]) {
t.Errorf("Expecting: %+v, received: %+v", expected, dsts[utils.TEST_SQL])
}
}
@@ -116,7 +116,7 @@ func TestMySQLSetGetTPRates(t *testing.T) {
rs.SetDurations()
}
rates := &utils.TPRate{
TPid: TEST_SQL,
TPid: utils.TEST_SQL,
RateId: RT_ID,
RateSlots: rtSlots,
}
@@ -124,7 +124,7 @@ func TestMySQLSetGetTPRates(t *testing.T) {
if err := mysqlDb.SetTpRates(mRates); err != nil {
t.Error(err.Error())
}
if rts, err := mysqlDb.GetTpRates(TEST_SQL, RT_ID); err != nil {
if rts, err := mysqlDb.GetTpRates(utils.TEST_SQL, RT_ID); err != nil {
t.Error(err.Error())
} else if !modelEqual(mRates[0], rts[0]) {
t.Errorf("Expecting: %+v, received: %+v", mRates, rts)
@@ -138,12 +138,12 @@ func TestMySQLSetGetTPDestinationRates(t *testing.T) {
DR_ID := "DR_1"
dr := &utils.DestinationRate{DestinationId: "DST_1", RateId: "RT_1", RoundingMethod: "*up", RoundingDecimals: 4}
eDrs := &utils.TPDestinationRate{TPid: TEST_SQL, DestinationRateId: DR_ID, DestinationRates: []*utils.DestinationRate{dr}}
eDrs := &utils.TPDestinationRate{TPid: utils.TEST_SQL, DestinationRateId: DR_ID, DestinationRates: []*utils.DestinationRate{dr}}
mdrs := APItoModelDestinationRate(eDrs)
if err := mysqlDb.SetTpDestinationRates(mdrs); err != nil {
t.Error(err.Error())
}
if drs, err := mysqlDb.GetTpDestinationRates(TEST_SQL, DR_ID, nil); err != nil {
if drs, err := mysqlDb.GetTpDestinationRates(utils.TEST_SQL, DR_ID, nil); err != nil {
t.Error(err.Error())
} else if !modelEqual(mdrs[0], drs[0]) {
t.Errorf("Expecting: %+v, received: %+v", mdrs, drs)
@@ -157,7 +157,7 @@ func TestMySQLSetGetTPRatingPlans(t *testing.T) {
RP_ID := "RP_1"
rbBinding := &utils.TPRatingPlanBinding{DestinationRatesId: "DR_1", TimingId: "TM_1", Weight: 10.0}
rp := &utils.TPRatingPlan{
TPid: TEST_SQL,
TPid: utils.TEST_SQL,
RatingPlanId: RP_ID,
RatingPlanBindings: []*utils.TPRatingPlanBinding{rbBinding},
}
@@ -165,7 +165,7 @@ func TestMySQLSetGetTPRatingPlans(t *testing.T) {
if err := mysqlDb.SetTpRatingPlans(mrp); err != nil {
t.Error(err.Error())
}
if drps, err := mysqlDb.GetTpRatingPlans(TEST_SQL, RP_ID, nil); err != nil {
if drps, err := mysqlDb.GetTpRatingPlans(utils.TEST_SQL, RP_ID, nil); err != nil {
t.Error(err.Error())
} else if !modelEqual(mrp[0], drps[0]) {
t.Errorf("Expecting: %+v, received: %+v", mrp, drps)
@@ -177,7 +177,7 @@ func TestMySQLSetGetTPRatingProfiles(t *testing.T) {
return
}
ras := []*utils.TPRatingActivation{&utils.TPRatingActivation{ActivationTime: "2012-01-01T00:00:00Z", RatingPlanId: "RP_1"}}
rp := &utils.TPRatingProfile{TPid: TEST_SQL, LoadId: TEST_SQL, Tenant: "cgrates.org", Category: "call", Direction: "*out", Subject: "*any", RatingPlanActivations: ras}
rp := &utils.TPRatingProfile{TPid: utils.TEST_SQL, LoadId: utils.TEST_SQL, Tenant: "cgrates.org", Category: "call", Direction: "*out", Subject: "*any", RatingPlanActivations: ras}
mrp := APItoModelRatingProfile(rp)
if err := mysqlDb.SetTpRatingProfiles(mrp); err != nil {
t.Error(err.Error())
@@ -196,7 +196,7 @@ func TestMySQLSetGetTPSharedGroups(t *testing.T) {
}
SG_ID := "SG_1"
tpSgs := &utils.TPSharedGroups{
TPid: TEST_SQL,
TPid: utils.TEST_SQL,
SharedGroupsId: SG_ID,
SharedGroups: []*utils.TPSharedGroup{
&utils.TPSharedGroup{Account: "dan", Strategy: "*lowest_first", RatingSubject: "lowest_rates"},
@@ -206,7 +206,7 @@ func TestMySQLSetGetTPSharedGroups(t *testing.T) {
if err := mysqlDb.SetTpSharedGroups(mSgs); err != nil {
t.Error(err.Error())
}
if sgs, err := mysqlDb.GetTpSharedGroups(TEST_SQL, SG_ID); err != nil {
if sgs, err := mysqlDb.GetTpSharedGroups(utils.TEST_SQL, SG_ID); err != nil {
t.Error(err.Error())
} else if !modelEqual(mSgs[0], sgs[0]) {
t.Errorf("Expecting: %+v, received: %+v", mSgs, sgs)
@@ -219,7 +219,7 @@ func TestMySQLSetGetTPCdrStats(t *testing.T) {
}
CS_ID := "CDRSTATS_1"
setCS := &utils.TPCdrStats{
TPid: TEST_SQL,
TPid: utils.TEST_SQL,
CdrStatsId: CS_ID,
CdrStats: []*utils.TPCdrStat{
&utils.TPCdrStat{QueueLength: "10", TimeWindow: "10m", Metrics: "ASR", Tenants: "cgrates.org", Categories: "call"},
@@ -229,7 +229,7 @@ func TestMySQLSetGetTPCdrStats(t *testing.T) {
if err := mysqlDb.SetTpCdrStats(mcs); err != nil {
t.Error(err.Error())
}
if cs, err := mysqlDb.GetTpCdrStats(TEST_SQL, CS_ID); err != nil {
if cs, err := mysqlDb.GetTpCdrStats(utils.TEST_SQL, CS_ID); err != nil {
t.Error(err.Error())
} else if !modelEqual(mcs[0], cs[0]) {
t.Errorf("Expecting: %+v, received: %+v", mcs, cs)
@@ -242,7 +242,7 @@ func TestMySQLSetGetTPDerivedChargers(t *testing.T) {
}
dc := &utils.TPDerivedCharger{RunId: utils.DEFAULT_RUNID, ReqTypeField: "^" + utils.META_PREPAID, AccountField: "^rif", SubjectField: "^rif",
UsageField: "cgr_duration", SupplierField: "^supplier1"}
dcs := &utils.TPDerivedChargers{TPid: TEST_SQL, Direction: utils.OUT, Tenant: "cgrates.org", Category: "call", Account: "dan", Subject: "dan", DerivedChargers: []*utils.TPDerivedCharger{dc}}
dcs := &utils.TPDerivedChargers{TPid: utils.TEST_SQL, Direction: utils.OUT, Tenant: "cgrates.org", Category: "call", Account: "dan", Subject: "dan", DerivedChargers: []*utils.TPDerivedCharger{dc}}
mdcs := APItoModelDerivedCharger(dcs)
if err := mysqlDb.SetTpDerivedChargers(mdcs); err != nil {
@@ -263,12 +263,12 @@ func TestMySQLSetGetTPActions(t *testing.T) {
acts := []*utils.TPAction{
&utils.TPAction{Identifier: "*topup_reset", BalanceType: "*monetary", Direction: "*out", Units: 10, ExpiryTime: "*unlimited",
DestinationIds: "*any", BalanceWeight: 10, Weight: 10}}
tpActions := &utils.TPActions{TPid: TEST_SQL, ActionsId: ACTS_ID, Actions: acts}
tpActions := &utils.TPActions{TPid: utils.TEST_SQL, ActionsId: ACTS_ID, Actions: acts}
mas := APItoModelAction(tpActions)
if err := mysqlDb.SetTpActions(mas); err != nil {
t.Error(err.Error())
}
if rTpActs, err := mysqlDb.GetTpActions(TEST_SQL, ACTS_ID); err != nil {
if rTpActs, err := mysqlDb.GetTpActions(utils.TEST_SQL, ACTS_ID); err != nil {
t.Error(err.Error())
} else if !modelEqual(mas[0], rTpActs[0]) {
t.Errorf("Expecting: %+v, received: %+v", mas, rTpActs)
@@ -281,7 +281,7 @@ func TestMySQLTPActionTimings(t *testing.T) {
}
AP_ID := "AP_1"
ap := &utils.TPActionPlan{
TPid: TEST_SQL,
TPid: utils.TEST_SQL,
ActionPlanId: AP_ID,
ActionPlan: []*utils.TPActionTiming{&utils.TPActionTiming{ActionsId: "ACTS_1", TimingId: "TM_1", Weight: 10.0}},
}
@@ -289,7 +289,7 @@ func TestMySQLTPActionTimings(t *testing.T) {
if err := mysqlDb.SetTpActionPlans(maps); err != nil {
t.Error(err.Error())
}
if rAP, err := mysqlDb.GetTpActionPlans(TEST_SQL, AP_ID); err != nil {
if rAP, err := mysqlDb.GetTpActionPlans(utils.TEST_SQL, AP_ID); err != nil {
t.Error(err.Error())
} else if !modelEqual(maps[0], rAP[0]) {
t.Errorf("Expecting: %+v, received: %+v", maps, rAP)
@@ -312,15 +312,15 @@ func TestMySQLSetGetTPActionTriggers(t *testing.T) {
ActionsId: "LOG_BALANCE",
}
atrgs := &utils.TPActionTriggers{
TPid: TEST_SQL,
ActionTriggersId: TEST_SQL,
TPid: utils.TEST_SQL,
ActionTriggersId: utils.TEST_SQL,
ActionTriggers: []*utils.TPActionTrigger{atrg},
}
matrg := APItoModelActionTrigger(atrgs)
if err := mysqlDb.SetTpActionTriggers(matrg); err != nil {
t.Error("Unexpected error: ", err.Error())
}
if rcvMpAtrgs, err := mysqlDb.GetTpActionTriggers(TEST_SQL, TEST_SQL); err != nil {
if rcvMpAtrgs, err := mysqlDb.GetTpActionTriggers(utils.TEST_SQL, utils.TEST_SQL); err != nil {
t.Error("Unexpected error: ", err.Error())
} else if !modelEqual(matrg[0], rcvMpAtrgs[0]) {
t.Errorf("Expecting: %v, received: %v", matrg, rcvMpAtrgs)
@@ -331,7 +331,7 @@ func TestMySQLSetGetTpAccountActions(t *testing.T) {
if !*testLocal {
return
}
aa := &utils.TPAccountActions{TPid: TEST_SQL, Tenant: "cgrates.org", Account: "1001",
aa := &utils.TPAccountActions{TPid: utils.TEST_SQL, Tenant: "cgrates.org", Account: "1001",
Direction: "*out", ActionPlanId: "PREPAID_10", ActionTriggersId: "STANDARD_TRIGGERS"}
maa := APItoModelAccountAction(aa)
if err := mysqlDb.SetTpAccountActions([]TpAccountAction{*maa}); err != nil {
@@ -348,7 +348,7 @@ func TestMySQLGetTPIds(t *testing.T) {
if !*testLocal {
return
}
eTPIds := []string{TEST_SQL}
eTPIds := []string{utils.TEST_SQL}
if tpIds, err := mysqlDb.GetTpIds(); err != nil {
t.Error(err.Error())
} else if !reflect.DeepEqual(eTPIds, tpIds) {
@@ -361,28 +361,28 @@ func TestMySQLRemoveTPData(t *testing.T) {
return
}
// Create Timings
tm := &utils.ApierTPTiming{TPid: TEST_SQL, TimingId: "ALWAYS", Time: "00:00:00"}
tm := &utils.ApierTPTiming{TPid: utils.TEST_SQL, TimingId: "ALWAYS", Time: "00:00:00"}
tms := APItoModelTiming(tm)
if err := mysqlDb.SetTpTimings([]TpTiming{*tms}); err != nil {
t.Error(err.Error())
}
if tmgs, err := mysqlDb.GetTpTimings(TEST_SQL, tm.TimingId); err != nil {
if tmgs, err := mysqlDb.GetTpTimings(utils.TEST_SQL, tm.TimingId); err != nil {
t.Error(err.Error())
} else if len(tmgs) == 0 {
t.Error("Could not store TPTiming")
}
// Remove Timings
if err := mysqlDb.RemTpData(utils.TBL_TP_TIMINGS, TEST_SQL, tm.TimingId); err != nil {
if err := mysqlDb.RemTpData(utils.TBL_TP_TIMINGS, utils.TEST_SQL, tm.TimingId); err != nil {
t.Error(err.Error())
}
if tmgs, err := mysqlDb.GetTpTimings(TEST_SQL, tm.TimingId); err != nil {
if tmgs, err := mysqlDb.GetTpTimings(utils.TEST_SQL, tm.TimingId); err != nil {
t.Error(err)
} else if len(tmgs) != 0 {
t.Errorf("Timings should be empty, got instead: %+v", tmgs)
}
// Create RatingProfile
ras := []*utils.TPRatingActivation{&utils.TPRatingActivation{ActivationTime: "2012-01-01T00:00:00Z", RatingPlanId: "RETAIL1"}}
rp := &utils.TPRatingProfile{TPid: TEST_SQL, LoadId: TEST_SQL, Tenant: "cgrates.org", Category: "call", Direction: "*out", Subject: "*any", RatingPlanActivations: ras}
rp := &utils.TPRatingProfile{TPid: utils.TEST_SQL, LoadId: utils.TEST_SQL, Tenant: "cgrates.org", Category: "call", Direction: "*out", Subject: "*any", RatingPlanActivations: ras}
mrp := APItoModelRatingProfile(rp)
if err := mysqlDb.SetTpRatingProfiles(mrp); err != nil {
t.Error(err.Error())
@@ -402,7 +402,7 @@ func TestMySQLRemoveTPData(t *testing.T) {
t.Errorf("RatingProfiles different than 0: %+v", rps)
}
// Create AccountActions
aa := &utils.TPAccountActions{TPid: TEST_SQL, LoadId: TEST_SQL, Tenant: "cgrates.org", Account: "1001",
aa := &utils.TPAccountActions{TPid: utils.TEST_SQL, LoadId: utils.TEST_SQL, Tenant: "cgrates.org", Account: "1001",
Direction: "*out", ActionPlanId: "PREPAID_10", ActionTriggersId: "STANDARD_TRIGGERS"}
maa := APItoModelAccountAction(aa)
if err := mysqlDb.SetTpAccountActions([]TpAccountAction{*maa}); err != nil {
@@ -426,7 +426,7 @@ func TestMySQLRemoveTPData(t *testing.T) {
if err := mysqlDb.SetTpTimings([]TpTiming{*tms}); err != nil {
t.Error(err.Error())
}
if tmgs, err := mysqlDb.GetTpTimings(TEST_SQL, tm.TimingId); err != nil {
if tmgs, err := mysqlDb.GetTpTimings(utils.TEST_SQL, tm.TimingId); err != nil {
t.Error(err.Error())
} else if len(tmgs) == 0 {
t.Error("Could not store TPTiming")
@@ -450,11 +450,11 @@ func TestMySQLRemoveTPData(t *testing.T) {
t.Error("Could not create TPAccountActions")
}
// Remove TariffPlan completely
if err := mysqlDb.RemTpData("", TEST_SQL); err != nil {
if err := mysqlDb.RemTpData("", utils.TEST_SQL); err != nil {
t.Error(err.Error())
}
// Make sure we have removed it
if tms, err := mysqlDb.GetTpTimings(TEST_SQL, tm.TimingId); err != nil {
if tms, err := mysqlDb.GetTpTimings(utils.TEST_SQL, tm.TimingId); err != nil {
t.Error(err)
} else if len(tms) != 0 {
t.Errorf("Non empty timings: %+v", tms)
@@ -477,23 +477,23 @@ func TestMySQLSetCdr(t *testing.T) {
}
cgrCdr1 := &CgrCdr{utils.TOR: utils.VOICE, utils.ACCID: "aaa1", utils.CDRHOST: "192.168.1.1", utils.REQTYPE: utils.META_RATED, utils.DIRECTION: "*out", utils.TENANT: "cgrates.org",
utils.CATEGORY: "call", utils.ACCOUNT: "1001", utils.SUBJECT: "1001", utils.DESTINATION: "1002", utils.SETUP_TIME: "2013-11-08T08:42:20Z",
utils.ANSWER_TIME: "2013-11-08T08:42:26Z", utils.USAGE: "10s", utils.PDD: "4s", utils.SUPPLIER: "SUPPL1", "field_extr1": "val_extr1", "fieldextr2": "valextr2", utils.CDRSOURCE: TEST_SQL}
utils.ANSWER_TIME: "2013-11-08T08:42:26Z", utils.USAGE: "10s", utils.PDD: "4s", utils.SUPPLIER: "SUPPL1", "field_extr1": "val_extr1", "fieldextr2": "valextr2", utils.CDRSOURCE: utils.TEST_SQL}
cgrCdr2 := &CgrCdr{utils.TOR: utils.VOICE, utils.ACCID: "aaa2", utils.CDRHOST: "192.168.1.1", utils.REQTYPE: utils.META_PREPAID, utils.DIRECTION: "*out", utils.TENANT: "cgrates.org",
utils.CATEGORY: "call", utils.ACCOUNT: "1001", utils.SUBJECT: "1001", utils.DESTINATION: "1002", utils.SETUP_TIME: "2013-11-08T08:42:22Z",
utils.ANSWER_TIME: "2013-11-08T08:42:26Z", utils.USAGE: "20", utils.PDD: "7s", utils.SUPPLIER: "SUPPL1", "field_extr1": "val_extr1", "fieldextr2": "valextr2", "cdrsource": TEST_SQL}
utils.ANSWER_TIME: "2013-11-08T08:42:26Z", utils.USAGE: "20", utils.PDD: "7s", utils.SUPPLIER: "SUPPL1", "field_extr1": "val_extr1", "fieldextr2": "valextr2", "cdrsource": utils.TEST_SQL}
cgrCdr3 := &CgrCdr{utils.TOR: utils.VOICE, utils.ACCID: "aaa3", utils.CDRHOST: "192.168.1.1", utils.REQTYPE: utils.META_RATED, utils.DIRECTION: "*out", utils.TENANT: "cgrates.org",
utils.CATEGORY: "premium_call", utils.ACCOUNT: "1002", utils.SUBJECT: "1002", utils.DESTINATION: "1001", utils.SETUP_TIME: "2013-11-07T08:42:24Z",
utils.ANSWER_TIME: "2013-11-07T08:42:26Z", utils.USAGE: "60s", utils.PDD: "4s", utils.SUPPLIER: "SUPPL1", "field_extr1": "val_extr1", "fieldextr2": "valextr2", "cdrsource": TEST_SQL}
utils.ANSWER_TIME: "2013-11-07T08:42:26Z", utils.USAGE: "60s", utils.PDD: "4s", utils.SUPPLIER: "SUPPL1", "field_extr1": "val_extr1", "fieldextr2": "valextr2", "cdrsource": utils.TEST_SQL}
cgrCdr4 := &CgrCdr{utils.TOR: utils.VOICE, utils.ACCID: "aaa4", utils.CDRHOST: "192.168.1.2", utils.REQTYPE: utils.META_PSEUDOPREPAID, utils.DIRECTION: "*out", utils.TENANT: "itsyscom.com",
utils.CATEGORY: "call", utils.ACCOUNT: "1001", utils.SUBJECT: "1001", utils.DESTINATION: "+4986517174964", utils.SETUP_TIME: "2013-11-07T08:42:21Z",
utils.ANSWER_TIME: "2013-11-07T08:42:26Z", utils.USAGE: "1m2s", utils.PDD: "4s", utils.SUPPLIER: "SUPPL1", "field_extr1": "val_extr1", "fieldextr2": "valextr2", "cdrsource": TEST_SQL}
utils.ANSWER_TIME: "2013-11-07T08:42:26Z", utils.USAGE: "1m2s", utils.PDD: "4s", utils.SUPPLIER: "SUPPL1", "field_extr1": "val_extr1", "fieldextr2": "valextr2", "cdrsource": utils.TEST_SQL}
cgrCdr5 := &CgrCdr{utils.TOR: utils.VOICE, utils.ACCID: "aaa5", utils.CDRHOST: "192.168.1.2", utils.REQTYPE: utils.META_POSTPAID, utils.DIRECTION: "*out", utils.TENANT: "itsyscom.com",
utils.CATEGORY: "call", utils.ACCOUNT: "1002", utils.SUBJECT: "1002", utils.DESTINATION: "+4986517174963", utils.SETUP_TIME: "2013-11-07T08:42:25Z",
utils.ANSWER_TIME: "2013-11-07T08:42:26Z", utils.USAGE: "15s", utils.PDD: "7s", utils.SUPPLIER: "SUPPL1", "field_extr1": "val_extr1", "fieldextr2": "valextr2", "cdrsource": TEST_SQL}
utils.ANSWER_TIME: "2013-11-07T08:42:26Z", utils.USAGE: "15s", utils.PDD: "7s", utils.SUPPLIER: "SUPPL1", "field_extr1": "val_extr1", "fieldextr2": "valextr2", "cdrsource": utils.TEST_SQL}
for _, cdr := range []*CgrCdr{cgrCdr1, cgrCdr2, cgrCdr3, cgrCdr4, cgrCdr5} {
if err := mysqlDb.SetCdr(cdr.AsStoredCdr()); err != nil {
@@ -514,7 +514,7 @@ func TestMySQLSetCdr(t *testing.T) {
ExtraFields: map[string]string{"field_extr1": "val_extr1", "fieldextr2": "valextr2"},
MediationRunId: utils.DEFAULT_RUNID, Cost: 0.201}
strCdr2.CgrId = utils.Sha1(strCdr2.AccId, strCdr2.SetupTime.String())
strCdr3 := &StoredCdr{TOR: utils.VOICE, AccId: "bbb3", CdrHost: "192.168.1.1", CdrSource: TEST_SQL, ReqType: utils.META_RATED,
strCdr3 := &StoredCdr{TOR: utils.VOICE, AccId: "bbb3", CdrHost: "192.168.1.1", CdrSource: utils.TEST_SQL, ReqType: utils.META_RATED,
Direction: "*out", Tenant: "itsyscom.com", Category: "call", Account: "1002", Subject: "1000", Destination: "+4986517174963",
SetupTime: time.Date(2013, 12, 7, 8, 42, 24, 0, time.UTC), AnswerTime: time.Date(2013, 12, 7, 8, 42, 26, 0, time.UTC),
Usage: time.Duration(10) * time.Second, Pdd: time.Duration(3) * time.Second, Supplier: "SUPPL1",
@@ -547,7 +547,7 @@ func TestMySQLSetRatedCdr(t *testing.T) {
ExtraFields: map[string]string{"field_extr1": "val_extr1", "fieldextr2": "valextr2"},
MediationRunId: utils.DEFAULT_RUNID, Cost: 0.201}
strCdr2.CgrId = utils.Sha1(strCdr2.AccId, strCdr2.SetupTime.String())
strCdr3 := &StoredCdr{TOR: utils.VOICE, AccId: "bbb3", CdrHost: "192.168.1.1", CdrSource: TEST_SQL, ReqType: utils.META_RATED,
strCdr3 := &StoredCdr{TOR: utils.VOICE, AccId: "bbb3", CdrHost: "192.168.1.1", CdrSource: utils.TEST_SQL, ReqType: utils.META_RATED,
Direction: "*out", Tenant: "itsyscom.com", Category: "call", Account: "1002", Subject: "1002", Destination: "+4986517174964",
SetupTime: time.Date(2013, 12, 7, 8, 42, 24, 0, time.UTC), AnswerTime: time.Date(2013, 12, 7, 8, 42, 26, 0, time.UTC),
Usage: time.Duration(10) * time.Second, Pdd: time.Duration(3) * time.Second, Supplier: "SUPPL1",
@@ -586,20 +586,20 @@ func TestMySQLCallCost(t *testing.T) {
},
},
}
if err := mysqlDb.LogCallCost(cgrId, TEST_SQL, utils.DEFAULT_RUNID, cc); err != nil {
if err := mysqlDb.LogCallCost(cgrId, utils.TEST_SQL, utils.DEFAULT_RUNID, cc); err != nil {
t.Error(err.Error())
}
if ccRcv, err := mysqlDb.GetCallCostLog(cgrId, TEST_SQL, utils.DEFAULT_RUNID); err != nil {
if ccRcv, err := mysqlDb.GetCallCostLog(cgrId, utils.TEST_SQL, utils.DEFAULT_RUNID); err != nil {
t.Error(err.Error())
} else if !reflect.DeepEqual(cc, ccRcv) {
t.Errorf("Expecting call cost: %v, received: %v", cc, ccRcv)
}
// UPDATE test here
cc.Category = "premium_call"
if err := mysqlDb.LogCallCost(cgrId, TEST_SQL, utils.DEFAULT_RUNID, cc); err != nil {
if err := mysqlDb.LogCallCost(cgrId, utils.TEST_SQL, utils.DEFAULT_RUNID, cc); err != nil {
t.Error(err.Error())
}
if ccRcv, err := mysqlDb.GetCallCostLog(cgrId, TEST_SQL, utils.DEFAULT_RUNID); err != nil {
if ccRcv, err := mysqlDb.GetCallCostLog(cgrId, utils.TEST_SQL, utils.DEFAULT_RUNID); err != nil {
t.Error(err.Error())
} else if !reflect.DeepEqual(cc, ccRcv) {
t.Errorf("Expecting call cost: %v, received: %v", cc, ccRcv)

View File

@@ -52,7 +52,7 @@ func NewPostgresStorage(host, port, name, user, password string, maxConn, maxIdl
}
func (self *PostgresStorage) Flush(scriptsPath string) (err error) {
for _, scriptName := range []string{CREATE_CDRS_TABLES_SQL, CREATE_TARIFFPLAN_TABLES_SQL} {
for _, scriptName := range []string{utils.CREATE_CDRS_TABLES_SQL, utils.CREATE_TARIFFPLAN_TABLES_SQL} {
if err := self.CreateTablesFromScript(path.Join(scriptsPath, scriptName)); err != nil {
return err
}

View File

@@ -43,7 +43,7 @@ func TestPSQLCreateTables(t *testing.T) {
} else {
psqlDb = d.(*PostgresStorage)
}
for _, scriptName := range []string{CREATE_CDRS_TABLES_SQL, CREATE_TARIFFPLAN_TABLES_SQL} {
for _, scriptName := range []string{utils.CREATE_CDRS_TABLES_SQL, utils.CREATE_TARIFFPLAN_TABLES_SQL} {
if err := psqlDb.CreateTablesFromScript(path.Join(*dataDir, "storage", utils.POSTGRES, scriptName)); err != nil {
t.Error("Error on psqlDb creation: ", err.Error())
return // No point in going further
@@ -60,13 +60,13 @@ func TestPSQLSetGetTPTiming(t *testing.T) {
if !*testLocal {
return
}
tm := &utils.ApierTPTiming{TPid: TEST_SQL, TimingId: "ALWAYS", Time: "00:00:00"}
tm := &utils.ApierTPTiming{TPid: utils.TEST_SQL, TimingId: "ALWAYS", Time: "00:00:00"}
mtm := APItoModelTiming(tm)
mtms := []TpTiming{*mtm}
if err := psqlDb.SetTpTimings(mtms); err != nil {
t.Error(err.Error())
}
if tmgs, err := psqlDb.GetTpTimings(TEST_SQL, tm.TimingId); err != nil {
if tmgs, err := psqlDb.GetTpTimings(utils.TEST_SQL, tm.TimingId); err != nil {
t.Error(err.Error())
} else if !modelEqual(mtms[0], tmgs[0]) {
t.Errorf("Expecting: %+v, received: %+v", mtms, tmgs)
@@ -76,7 +76,7 @@ func TestPSQLSetGetTPTiming(t *testing.T) {
if err := psqlDb.SetTpTimings(mtms); err != nil {
t.Error(err.Error())
}
if tmgs, err := psqlDb.GetTpTimings(TEST_SQL, tm.TimingId); err != nil {
if tmgs, err := psqlDb.GetTpTimings(utils.TEST_SQL, tm.TimingId); err != nil {
t.Error(err.Error())
} else if !modelEqual(mtms[0], tmgs[0]) {
t.Errorf("Expecting: %+v, received: %+v", mtms, tmgs)
@@ -87,17 +87,17 @@ func TestPSQLSetGetTPDestination(t *testing.T) {
if !*testLocal {
return
}
dst := &utils.TPDestination{TPid: TEST_SQL, DestinationId: TEST_SQL, Prefixes: []string{"+49", "+49151", "+49176"}}
dst := &utils.TPDestination{TPid: utils.TEST_SQL, DestinationId: utils.TEST_SQL, Prefixes: []string{"+49", "+49151", "+49176"}}
dests := APItoModelDestination(dst)
if err := psqlDb.SetTpDestinations(dests); err != nil {
t.Error(err.Error())
}
storData, err := psqlDb.GetTpDestinations(TEST_SQL, TEST_SQL)
storData, err := psqlDb.GetTpDestinations(utils.TEST_SQL, utils.TEST_SQL)
dsts, err := TpDestinations(storData).GetDestinations()
if err != nil {
t.Error(err.Error())
} else if len(dst.Prefixes) != len(dsts[TEST_SQL].Prefixes) {
t.Errorf("Expecting: %+v, received: %+v", dst, dsts[TEST_SQL])
} else if len(dst.Prefixes) != len(dsts[utils.TEST_SQL].Prefixes) {
t.Errorf("Expecting: %+v, received: %+v", dst, dsts[utils.TEST_SQL])
}
}
@@ -113,12 +113,12 @@ func TestPSQLSetGetTPRates(t *testing.T) {
for _, rs := range rtSlots {
rs.SetDurations()
}
expectedTPRate := &utils.TPRate{TPid: TEST_SQL, RateId: RT_ID, RateSlots: rtSlots}
expectedTPRate := &utils.TPRate{TPid: utils.TEST_SQL, RateId: RT_ID, RateSlots: rtSlots}
mRates := APItoModelRate(expectedTPRate)
if err := psqlDb.SetTpRates(mRates); err != nil {
t.Error(err.Error())
}
rts, err := psqlDb.GetTpRates(TEST_SQL, RT_ID)
rts, err := psqlDb.GetTpRates(utils.TEST_SQL, RT_ID)
trts, err := TpRates(rts).GetRates()
if err != nil {
t.Error(err.Error())
@@ -133,12 +133,12 @@ func TestPSQLSetGetTPDestinationRates(t *testing.T) {
}
DR_ID := "DR_1"
dr := &utils.DestinationRate{DestinationId: "DST_1", RateId: "RT_1", RoundingMethod: "*up", RoundingDecimals: 4}
eDrs := &utils.TPDestinationRate{TPid: TEST_SQL, DestinationRateId: DR_ID, DestinationRates: []*utils.DestinationRate{dr}}
eDrs := &utils.TPDestinationRate{TPid: utils.TEST_SQL, DestinationRateId: DR_ID, DestinationRates: []*utils.DestinationRate{dr}}
mdrs := APItoModelDestinationRate(eDrs)
if err := psqlDb.SetTpDestinationRates(mdrs); err != nil {
t.Error(err.Error())
}
if drs, err := psqlDb.GetTpDestinationRates(TEST_SQL, DR_ID, nil); err != nil {
if drs, err := psqlDb.GetTpDestinationRates(utils.TEST_SQL, DR_ID, nil); err != nil {
t.Error(err.Error())
} else if !modelEqual(mdrs[0], drs[0]) {
t.Errorf("Expecting: %+v, received: %+v", mdrs, drs)
@@ -152,7 +152,7 @@ func TestPSQLSetGetTPRatingPlans(t *testing.T) {
RP_ID := "RP_1"
rbBinding := &utils.TPRatingPlanBinding{DestinationRatesId: "DR_1", TimingId: "TM_1", Weight: 10.0}
rp := &utils.TPRatingPlan{
TPid: TEST_SQL,
TPid: utils.TEST_SQL,
RatingPlanId: RP_ID,
RatingPlanBindings: []*utils.TPRatingPlanBinding{rbBinding},
}
@@ -161,7 +161,7 @@ func TestPSQLSetGetTPRatingPlans(t *testing.T) {
if err := psqlDb.SetTpRatingPlans(mrp); err != nil {
t.Error(err.Error())
}
if drps, err := psqlDb.GetTpRatingPlans(TEST_SQL, RP_ID, nil); err != nil {
if drps, err := psqlDb.GetTpRatingPlans(utils.TEST_SQL, RP_ID, nil); err != nil {
t.Error(err.Error())
} else if !modelEqual(mrp[0], drps[0]) {
t.Errorf("Expecting: %+v, received: %+v", mrp, drps)
@@ -173,7 +173,7 @@ func TestPSQLSetGetTPRatingProfiles(t *testing.T) {
return
}
ras := []*utils.TPRatingActivation{&utils.TPRatingActivation{ActivationTime: "2012-01-01T00:00:00Z", RatingPlanId: "RP_1"}}
rp := &utils.TPRatingProfile{TPid: TEST_SQL, LoadId: TEST_SQL, Tenant: "cgrates.org", Category: "call", Direction: "*out", Subject: "*any", RatingPlanActivations: ras}
rp := &utils.TPRatingProfile{TPid: utils.TEST_SQL, LoadId: utils.TEST_SQL, Tenant: "cgrates.org", Category: "call", Direction: "*out", Subject: "*any", RatingPlanActivations: ras}
mrp := APItoModelRatingProfile(rp)
if err := psqlDb.SetTpRatingProfiles(mrp); err != nil {
@@ -192,7 +192,7 @@ func TestPSQLSetGetTPSharedGroups(t *testing.T) {
}
SG_ID := "SG_1"
tpSgs := &utils.TPSharedGroups{
TPid: TEST_SQL,
TPid: utils.TEST_SQL,
SharedGroupsId: SG_ID,
SharedGroups: []*utils.TPSharedGroup{
&utils.TPSharedGroup{Account: "dan", Strategy: "*lowest_first", RatingSubject: "lowest_rates"},
@@ -202,7 +202,7 @@ func TestPSQLSetGetTPSharedGroups(t *testing.T) {
if err := psqlDb.SetTpSharedGroups(mSgs); err != nil {
t.Error(err.Error())
}
if sgs, err := psqlDb.GetTpSharedGroups(TEST_SQL, SG_ID); err != nil {
if sgs, err := psqlDb.GetTpSharedGroups(utils.TEST_SQL, SG_ID); err != nil {
t.Error(err.Error())
} else if !modelEqual(mSgs[0], sgs[0]) {
t.Errorf("Expecting: %+v, received: %+v", mSgs, sgs)
@@ -215,7 +215,7 @@ func TestPSQLSetGetTPCdrStats(t *testing.T) {
}
CS_ID := "CDRSTATS_1"
setCS := &utils.TPCdrStats{
TPid: TEST_SQL,
TPid: utils.TEST_SQL,
CdrStatsId: CS_ID,
CdrStats: []*utils.TPCdrStat{
&utils.TPCdrStat{QueueLength: "10", TimeWindow: "10m", Metrics: "ASR", Tenants: "cgrates.org", Categories: "call"},
@@ -225,7 +225,7 @@ func TestPSQLSetGetTPCdrStats(t *testing.T) {
if err := psqlDb.SetTpCdrStats(mcs); err != nil {
t.Error(err.Error())
}
if cs, err := psqlDb.GetTpCdrStats(TEST_SQL, CS_ID); err != nil {
if cs, err := psqlDb.GetTpCdrStats(utils.TEST_SQL, CS_ID); err != nil {
t.Error(err.Error())
} else if !modelEqual(mcs[0], cs[0]) {
t.Errorf("Expecting: %+v, received: %+v", mcs, cs)
@@ -238,7 +238,7 @@ func TestPSQLSetGetTPDerivedChargers(t *testing.T) {
}
dc := &utils.TPDerivedCharger{RunId: utils.DEFAULT_RUNID, ReqTypeField: "^" + utils.META_PREPAID, AccountField: "^rif", SubjectField: "^rif",
UsageField: "cgr_duration", SupplierField: "^supplier1"}
dcs := &utils.TPDerivedChargers{TPid: TEST_SQL, Direction: utils.OUT, Tenant: "cgrates.org", Category: "call", Account: "dan", Subject: "dan", DerivedChargers: []*utils.TPDerivedCharger{dc}}
dcs := &utils.TPDerivedChargers{TPid: utils.TEST_SQL, Direction: utils.OUT, Tenant: "cgrates.org", Category: "call", Account: "dan", Subject: "dan", DerivedChargers: []*utils.TPDerivedCharger{dc}}
mdcs := APItoModelDerivedCharger(dcs)
if err := psqlDb.SetTpDerivedChargers(mdcs); err != nil {
t.Error(err.Error())
@@ -258,12 +258,12 @@ func TestPSQLSetGetTPActions(t *testing.T) {
acts := []*utils.TPAction{
&utils.TPAction{Identifier: "*topup_reset", BalanceType: "*monetary", Direction: "*out", Units: 10, ExpiryTime: "*unlimited",
DestinationIds: "*any", BalanceWeight: 10, Weight: 10}}
tpActions := &utils.TPActions{TPid: TEST_SQL, ActionsId: ACTS_ID, Actions: acts}
tpActions := &utils.TPActions{TPid: utils.TEST_SQL, ActionsId: ACTS_ID, Actions: acts}
mas := APItoModelAction(tpActions)
if err := psqlDb.SetTpActions(mas); err != nil {
t.Error(err.Error())
}
if rTpActs, err := psqlDb.GetTpActions(TEST_SQL, ACTS_ID); err != nil {
if rTpActs, err := psqlDb.GetTpActions(utils.TEST_SQL, ACTS_ID); err != nil {
t.Error(err.Error())
} else if !modelEqual(mas[0], rTpActs[0]) {
t.Errorf("Expecting: %+v, received: %+v", mas, rTpActs)
@@ -276,7 +276,7 @@ func TestPSQLTPActionTimings(t *testing.T) {
}
AP_ID := "AP_1"
ap := &utils.TPActionPlan{
TPid: TEST_SQL,
TPid: utils.TEST_SQL,
ActionPlanId: AP_ID,
ActionPlan: []*utils.TPActionTiming{&utils.TPActionTiming{ActionsId: "ACTS_1", TimingId: "TM_1", Weight: 10.0}},
}
@@ -284,7 +284,7 @@ func TestPSQLTPActionTimings(t *testing.T) {
if err := psqlDb.SetTpActionPlans(maps); err != nil {
t.Error(err.Error())
}
if rAP, err := psqlDb.GetTpActionPlans(TEST_SQL, AP_ID); err != nil {
if rAP, err := psqlDb.GetTpActionPlans(utils.TEST_SQL, AP_ID); err != nil {
t.Error(err.Error())
} else if !modelEqual(maps[0], rAP[0]) {
t.Errorf("Expecting: %+v, received: %+v", maps, rAP)
@@ -307,15 +307,15 @@ func TestPSQLSetGetTPActionTriggers(t *testing.T) {
ActionsId: "LOG_BALANCE",
}
atrgs := &utils.TPActionTriggers{
TPid: TEST_SQL,
ActionTriggersId: TEST_SQL,
TPid: utils.TEST_SQL,
ActionTriggersId: utils.TEST_SQL,
ActionTriggers: []*utils.TPActionTrigger{atrg},
}
matrg := APItoModelActionTrigger(atrgs)
if err := psqlDb.SetTpActionTriggers(matrg); err != nil {
t.Error("Unexpected error: ", err.Error())
}
if rcvMpAtrgs, err := psqlDb.GetTpActionTriggers(TEST_SQL, TEST_SQL); err != nil {
if rcvMpAtrgs, err := psqlDb.GetTpActionTriggers(utils.TEST_SQL, utils.TEST_SQL); err != nil {
t.Error("Unexpected error: ", err.Error())
} else if !modelEqual(matrg[0], rcvMpAtrgs[0]) {
t.Errorf("Expecting: %v, received: %v", matrg, rcvMpAtrgs)
@@ -326,7 +326,7 @@ func TestPSQLSetGetTpAccountActions(t *testing.T) {
if !*testLocal {
return
}
aa := &utils.TPAccountActions{TPid: TEST_SQL, Tenant: "cgrates.org", Account: "1001",
aa := &utils.TPAccountActions{TPid: utils.TEST_SQL, Tenant: "cgrates.org", Account: "1001",
Direction: "*out", ActionPlanId: "PREPAID_10", ActionTriggersId: "STANDARD_TRIGGERS"}
maa := APItoModelAccountAction(aa)
if err := psqlDb.SetTpAccountActions([]TpAccountAction{*maa}); err != nil {
@@ -343,7 +343,7 @@ func TestPSQLGetTPIds(t *testing.T) {
if !*testLocal {
return
}
eTPIds := []string{TEST_SQL}
eTPIds := []string{utils.TEST_SQL}
if tpIds, err := psqlDb.GetTpIds(); err != nil {
t.Error(err.Error())
} else if !reflect.DeepEqual(eTPIds, tpIds) {
@@ -356,28 +356,28 @@ func TestPSQLRemoveTPData(t *testing.T) {
return
}
// Create Timings
tm := &utils.ApierTPTiming{TPid: TEST_SQL, TimingId: "ALWAYS", Time: "00:00:00"}
tm := &utils.ApierTPTiming{TPid: utils.TEST_SQL, TimingId: "ALWAYS", Time: "00:00:00"}
tms := APItoModelTiming(tm)
if err := psqlDb.SetTpTimings([]TpTiming{*tms}); err != nil {
t.Error(err.Error())
}
if tmgs, err := psqlDb.GetTpTimings(TEST_SQL, tm.TimingId); err != nil {
if tmgs, err := psqlDb.GetTpTimings(utils.TEST_SQL, tm.TimingId); err != nil {
t.Error(err.Error())
} else if len(tmgs) == 0 {
t.Error("Could not store TPTiming")
}
// Remove Timings
if err := psqlDb.RemTpData(utils.TBL_TP_TIMINGS, TEST_SQL, tm.TimingId); err != nil {
if err := psqlDb.RemTpData(utils.TBL_TP_TIMINGS, utils.TEST_SQL, tm.TimingId); err != nil {
t.Error(err.Error())
}
if tmgs, err := psqlDb.GetTpTimings(TEST_SQL, tm.TimingId); err != nil {
if tmgs, err := psqlDb.GetTpTimings(utils.TEST_SQL, tm.TimingId); err != nil {
t.Error(err)
} else if len(tmgs) != 0 {
t.Errorf("Timings should be empty, got instead: %+v", tmgs)
}
// Create RatingProfile
ras := []*utils.TPRatingActivation{&utils.TPRatingActivation{ActivationTime: "2012-01-01T00:00:00Z", RatingPlanId: "RETAIL1"}}
rp := &utils.TPRatingProfile{TPid: TEST_SQL, LoadId: TEST_SQL, Tenant: "cgrates.org", Category: "call", Direction: "*out", Subject: "*any", RatingPlanActivations: ras}
rp := &utils.TPRatingProfile{TPid: utils.TEST_SQL, LoadId: utils.TEST_SQL, Tenant: "cgrates.org", Category: "call", Direction: "*out", Subject: "*any", RatingPlanActivations: ras}
mrp := APItoModelRatingProfile(rp)
if err := psqlDb.SetTpRatingProfiles(mrp); err != nil {
t.Error(err.Error())
@@ -397,7 +397,7 @@ func TestPSQLRemoveTPData(t *testing.T) {
t.Errorf("RatingProfiles different than 0: %+v", rps)
}
// Create AccountActions
aa := &utils.TPAccountActions{TPid: TEST_SQL, LoadId: TEST_SQL, Tenant: "cgrates.org", Account: "1001",
aa := &utils.TPAccountActions{TPid: utils.TEST_SQL, LoadId: utils.TEST_SQL, Tenant: "cgrates.org", Account: "1001",
Direction: "*out", ActionPlanId: "PREPAID_10", ActionTriggersId: "STANDARD_TRIGGERS"}
maa := APItoModelAccountAction(aa)
if err := psqlDb.SetTpAccountActions([]TpAccountAction{*maa}); err != nil {
@@ -421,7 +421,7 @@ func TestPSQLRemoveTPData(t *testing.T) {
if err := psqlDb.SetTpTimings([]TpTiming{*tms}); err != nil {
t.Error(err.Error())
}
if tmgs, err := psqlDb.GetTpTimings(TEST_SQL, tm.TimingId); err != nil {
if tmgs, err := psqlDb.GetTpTimings(utils.TEST_SQL, tm.TimingId); err != nil {
t.Error(err.Error())
} else if len(tmgs) == 0 {
t.Error("Could not store TPTiming")
@@ -445,11 +445,11 @@ func TestPSQLRemoveTPData(t *testing.T) {
t.Error("Could not create TPAccountActions")
}
// Remove TariffPlan completely
if err := psqlDb.RemTpData("", TEST_SQL); err != nil {
if err := psqlDb.RemTpData("", utils.TEST_SQL); err != nil {
t.Error(err.Error())
}
// Make sure we have removed it
if tms, err := psqlDb.GetTpTimings(TEST_SQL, tm.TimingId); err != nil {
if tms, err := psqlDb.GetTpTimings(utils.TEST_SQL, tm.TimingId); err != nil {
t.Error(err)
} else if len(tms) != 0 {
t.Errorf("Non empty timings: %+v", tms)
@@ -472,23 +472,23 @@ func TestPSQLSetCdr(t *testing.T) {
}
cgrCdr1 := &CgrCdr{utils.TOR: utils.VOICE, utils.ACCID: "aaa1", utils.CDRHOST: "192.168.1.1", utils.REQTYPE: utils.META_RATED, utils.DIRECTION: "*out", utils.TENANT: "cgrates.org",
utils.CATEGORY: "call", utils.ACCOUNT: "1001", utils.SUBJECT: "1001", utils.DESTINATION: "1002", utils.SETUP_TIME: "2013-11-08T08:42:20Z",
utils.ANSWER_TIME: "2013-11-08T08:42:26Z", utils.USAGE: "10s", utils.PDD: "4s", utils.SUPPLIER: "SUPPL1", "field_extr1": "val_extr1", "fieldextr2": "valextr2", utils.CDRSOURCE: TEST_SQL}
utils.ANSWER_TIME: "2013-11-08T08:42:26Z", utils.USAGE: "10s", utils.PDD: "4s", utils.SUPPLIER: "SUPPL1", "field_extr1": "val_extr1", "fieldextr2": "valextr2", utils.CDRSOURCE: utils.TEST_SQL}
cgrCdr2 := &CgrCdr{utils.TOR: utils.VOICE, utils.ACCID: "aaa2", utils.CDRHOST: "192.168.1.1", utils.REQTYPE: utils.META_PREPAID, utils.DIRECTION: "*out", utils.TENANT: "cgrates.org",
utils.CATEGORY: "call", utils.ACCOUNT: "1001", utils.SUBJECT: "1001", utils.DESTINATION: "1002", utils.SETUP_TIME: "2013-11-08T08:42:22Z",
utils.ANSWER_TIME: "2013-11-08T08:42:26Z", utils.USAGE: "20", utils.PDD: "7s", utils.SUPPLIER: "SUPPL1", "field_extr1": "val_extr1", "fieldextr2": "valextr2", "cdrsource": TEST_SQL}
utils.ANSWER_TIME: "2013-11-08T08:42:26Z", utils.USAGE: "20", utils.PDD: "7s", utils.SUPPLIER: "SUPPL1", "field_extr1": "val_extr1", "fieldextr2": "valextr2", "cdrsource": utils.TEST_SQL}
cgrCdr3 := &CgrCdr{utils.TOR: utils.VOICE, utils.ACCID: "aaa3", utils.CDRHOST: "192.168.1.1", utils.REQTYPE: utils.META_RATED, utils.DIRECTION: "*out", utils.TENANT: "cgrates.org",
utils.CATEGORY: "premium_call", utils.ACCOUNT: "1002", utils.SUBJECT: "1002", utils.DESTINATION: "1001", utils.SETUP_TIME: "2013-11-07T08:42:24Z",
utils.ANSWER_TIME: "2013-11-07T08:42:26Z", utils.USAGE: "60s", utils.PDD: "4s", utils.SUPPLIER: "SUPPL1", "field_extr1": "val_extr1", "fieldextr2": "valextr2", "cdrsource": TEST_SQL}
utils.ANSWER_TIME: "2013-11-07T08:42:26Z", utils.USAGE: "60s", utils.PDD: "4s", utils.SUPPLIER: "SUPPL1", "field_extr1": "val_extr1", "fieldextr2": "valextr2", "cdrsource": utils.TEST_SQL}
cgrCdr4 := &CgrCdr{utils.TOR: utils.VOICE, utils.ACCID: "aaa4", utils.CDRHOST: "192.168.1.2", utils.REQTYPE: utils.META_PSEUDOPREPAID, utils.DIRECTION: "*out", utils.TENANT: "itsyscom.com",
utils.CATEGORY: "call", utils.ACCOUNT: "1001", utils.SUBJECT: "1001", utils.DESTINATION: "+4986517174964", utils.SETUP_TIME: "2013-11-07T08:42:21Z",
utils.ANSWER_TIME: "2013-11-07T08:42:26Z", utils.USAGE: "1m2s", utils.PDD: "4s", utils.SUPPLIER: "SUPPL1", "field_extr1": "val_extr1", "fieldextr2": "valextr2", "cdrsource": TEST_SQL}
utils.ANSWER_TIME: "2013-11-07T08:42:26Z", utils.USAGE: "1m2s", utils.PDD: "4s", utils.SUPPLIER: "SUPPL1", "field_extr1": "val_extr1", "fieldextr2": "valextr2", "cdrsource": utils.TEST_SQL}
cgrCdr5 := &CgrCdr{utils.TOR: utils.VOICE, utils.ACCID: "aaa5", utils.CDRHOST: "192.168.1.2", utils.REQTYPE: utils.META_POSTPAID, utils.DIRECTION: "*out", utils.TENANT: "itsyscom.com",
utils.CATEGORY: "call", utils.ACCOUNT: "1002", utils.SUBJECT: "1002", utils.DESTINATION: "+4986517174963", utils.SETUP_TIME: "2013-11-07T08:42:25Z",
utils.ANSWER_TIME: "2013-11-07T08:42:26Z", utils.USAGE: "15s", utils.PDD: "7s", utils.SUPPLIER: "SUPPL1", "field_extr1": "val_extr1", "fieldextr2": "valextr2", "cdrsource": TEST_SQL}
utils.ANSWER_TIME: "2013-11-07T08:42:26Z", utils.USAGE: "15s", utils.PDD: "7s", utils.SUPPLIER: "SUPPL1", "field_extr1": "val_extr1", "fieldextr2": "valextr2", "cdrsource": utils.TEST_SQL}
for _, cdr := range []*CgrCdr{cgrCdr1, cgrCdr2, cgrCdr3, cgrCdr4, cgrCdr5} {
if err := psqlDb.SetCdr(cdr.AsStoredCdr()); err != nil {
@@ -509,7 +509,7 @@ func TestPSQLSetCdr(t *testing.T) {
ExtraFields: map[string]string{"field_extr1": "val_extr1", "fieldextr2": "valextr2"},
MediationRunId: utils.DEFAULT_RUNID, Cost: 0.201}
strCdr2.CgrId = utils.Sha1(strCdr2.AccId, strCdr2.SetupTime.String())
strCdr3 := &StoredCdr{TOR: utils.VOICE, AccId: "bbb3", CdrHost: "192.168.1.1", CdrSource: TEST_SQL, ReqType: utils.META_RATED,
strCdr3 := &StoredCdr{TOR: utils.VOICE, AccId: "bbb3", CdrHost: "192.168.1.1", CdrSource: utils.TEST_SQL, ReqType: utils.META_RATED,
Direction: "*out", Tenant: "itsyscom.com", Category: "call", Account: "1002", Subject: "1000", Destination: "+4986517174963",
SetupTime: time.Date(2013, 12, 7, 8, 42, 24, 0, time.UTC), AnswerTime: time.Date(2013, 12, 7, 8, 42, 26, 0, time.UTC),
Usage: time.Duration(10) * time.Second, Pdd: time.Duration(3) * time.Second, Supplier: "SUPPL1",
@@ -548,20 +548,20 @@ func TestPSQLCallCost(t *testing.T) {
},
},
}
if err := psqlDb.LogCallCost(cgrId, TEST_SQL, utils.DEFAULT_RUNID, cc); err != nil {
if err := psqlDb.LogCallCost(cgrId, utils.TEST_SQL, utils.DEFAULT_RUNID, cc); err != nil {
t.Error(err.Error())
}
if ccRcv, err := psqlDb.GetCallCostLog(cgrId, TEST_SQL, utils.DEFAULT_RUNID); err != nil {
if ccRcv, err := psqlDb.GetCallCostLog(cgrId, utils.TEST_SQL, utils.DEFAULT_RUNID); err != nil {
t.Error(err.Error())
} else if !reflect.DeepEqual(cc, ccRcv) {
t.Errorf("Expecting call cost: %v, received: %v", cc, ccRcv)
}
// UPDATE test here
cc.Category = "premium_call"
if err := psqlDb.LogCallCost(cgrId, TEST_SQL, utils.DEFAULT_RUNID, cc); err != nil {
if err := psqlDb.LogCallCost(cgrId, utils.TEST_SQL, utils.DEFAULT_RUNID, cc); err != nil {
t.Error(err.Error())
}
if ccRcv, err := psqlDb.GetCallCostLog(cgrId, TEST_SQL, utils.DEFAULT_RUNID); err != nil {
if ccRcv, err := psqlDb.GetCallCostLog(cgrId, utils.TEST_SQL, utils.DEFAULT_RUNID); err != nil {
t.Error(err.Error())
} else if !reflect.DeepEqual(cc, ccRcv) {
t.Errorf("Expecting call cost: %v, received: %v", cc, ccRcv)
@@ -586,7 +586,7 @@ func TestPSQLSetRatedCdr(t *testing.T) {
ExtraFields: map[string]string{"field_extr1": "val_extr1", "fieldextr2": "valextr2"},
MediationRunId: utils.DEFAULT_RUNID, Cost: 0.201}
strCdr2.CgrId = utils.Sha1(strCdr2.AccId, strCdr2.SetupTime.String())
strCdr3 := &StoredCdr{TOR: utils.VOICE, AccId: "bbb3", CdrHost: "192.168.1.1", CdrSource: TEST_SQL, ReqType: utils.META_RATED,
strCdr3 := &StoredCdr{TOR: utils.VOICE, AccId: "bbb3", CdrHost: "192.168.1.1", CdrSource: utils.TEST_SQL, ReqType: utils.META_RATED,
Direction: "*out", Tenant: "itsyscom.com", Category: "call", Account: "1002", Subject: "1002", Destination: "+4986517174964",
SetupTime: time.Date(2013, 12, 7, 8, 42, 24, 0, time.UTC), AnswerTime: time.Date(2013, 12, 7, 8, 42, 26, 0, time.UTC),
Usage: time.Duration(10) * time.Second, Pdd: time.Duration(3) * time.Second, Supplier: "SUPPL1",

View File

@@ -66,26 +66,72 @@ func (rs *RedisStorage) GetKeysForPrefix(prefix string) ([]string, error) {
return rs.db.Keys(prefix + "*")
}
func (rs *RedisStorage) CacheRating(dKeys, rpKeys, rpfKeys, alsKeys, lcrKeys, dcsKeys []string) (err error) {
func (rs *RedisStorage) CacheAll() error {
return rs.Cache(nil, nil, nil, nil, nil, nil, nil, nil, nil)
}
func (rs *RedisStorage) CachePrefixes(prefixes ...string) error {
pm := map[string][]string{
utils.DESTINATION_PREFIX: []string{},
utils.RATING_PLAN_PREFIX: []string{},
utils.RATING_PROFILE_PREFIX: []string{},
utils.RP_ALIAS_PREFIX: []string{},
utils.LCR_PREFIX: []string{},
utils.DERIVEDCHARGERS_PREFIX: []string{},
utils.ACTION_PREFIX: []string{},
utils.SHARED_GROUP_PREFIX: []string{},
utils.ACC_ALIAS_PREFIX: []string{},
}
for _, prefix := range prefixes {
if _, found := pm[prefix]; !found {
return utils.ErrNotFound
}
pm[prefix] = nil
}
return rs.Cache(pm[utils.DESTINATION_PREFIX], pm[utils.RATING_PLAN_PREFIX], pm[utils.RATING_PROFILE_PREFIX], pm[utils.RP_ALIAS_PREFIX], pm[utils.LCR_PREFIX], pm[utils.DERIVEDCHARGERS_PREFIX], pm[utils.ACTION_PREFIX], pm[utils.SHARED_GROUP_PREFIX], pm[utils.ACC_ALIAS_PREFIX])
}
func (rs *RedisStorage) CachePrefixValues(prefixes map[string][]string) error {
pm := map[string][]string{
utils.DESTINATION_PREFIX: []string{},
utils.RATING_PLAN_PREFIX: []string{},
utils.RATING_PROFILE_PREFIX: []string{},
utils.RP_ALIAS_PREFIX: []string{},
utils.LCR_PREFIX: []string{},
utils.DERIVEDCHARGERS_PREFIX: []string{},
utils.ACTION_PREFIX: []string{},
utils.SHARED_GROUP_PREFIX: []string{},
utils.ACC_ALIAS_PREFIX: []string{},
}
for prefix, ids := range prefixes {
if _, found := pm[prefix]; !found {
return utils.ErrNotFound
}
pm[prefix] = ids
}
return rs.Cache(pm[utils.DESTINATION_PREFIX], pm[utils.RATING_PLAN_PREFIX], pm[utils.RATING_PROFILE_PREFIX], pm[utils.RP_ALIAS_PREFIX], pm[utils.LCR_PREFIX], pm[utils.DERIVEDCHARGERS_PREFIX], pm[utils.ACTION_PREFIX], pm[utils.SHARED_GROUP_PREFIX], pm[utils.ACC_ALIAS_PREFIX])
}
func (rs *RedisStorage) Cache(dKeys, rpKeys, rpfKeys, plsKeys, lcrKeys, dcsKeys, actKeys, shgKeys, alsKeys []string) (err error) {
cache2go.BeginTransaction()
if dKeys == nil || (float64(cache2go.CountEntries(DESTINATION_PREFIX))*DESTINATIONS_LOAD_THRESHOLD < float64(len(dKeys))) {
if dKeys == nil || (float64(cache2go.CountEntries(utils.DESTINATION_PREFIX))*utils.DESTINATIONS_LOAD_THRESHOLD < float64(len(dKeys))) {
// if need to load more than a half of exiting keys load them all
Logger.Info("Caching all destinations")
if dKeys, err = rs.db.Keys(DESTINATION_PREFIX + "*"); err != nil {
if dKeys, err = rs.db.Keys(utils.DESTINATION_PREFIX + "*"); err != nil {
cache2go.RollbackTransaction()
return err
}
cache2go.RemPrefixKey(DESTINATION_PREFIX)
cache2go.RemPrefixKey(utils.DESTINATION_PREFIX)
} else if len(dKeys) != 0 {
Logger.Info(fmt.Sprintf("Caching destinations: %v", dKeys))
CleanStalePrefixes(dKeys)
}
for _, key := range dKeys {
if len(key) <= len(DESTINATION_PREFIX) {
if len(key) <= len(utils.DESTINATION_PREFIX) {
Logger.Warning(fmt.Sprintf("Got malformed destination id: %s", key))
continue
}
if _, err = rs.GetDestination(key[len(DESTINATION_PREFIX):]); err != nil {
if _, err = rs.GetDestination(key[len(utils.DESTINATION_PREFIX):]); err != nil {
cache2go.RollbackTransaction()
return err
}
@@ -95,17 +141,17 @@ func (rs *RedisStorage) CacheRating(dKeys, rpKeys, rpfKeys, alsKeys, lcrKeys, dc
}
if rpKeys == nil {
Logger.Info("Caching all rating plans")
if rpKeys, err = rs.db.Keys(RATING_PLAN_PREFIX + "*"); err != nil {
if rpKeys, err = rs.db.Keys(utils.RATING_PLAN_PREFIX + "*"); err != nil {
cache2go.RollbackTransaction()
return err
}
cache2go.RemPrefixKey(RATING_PLAN_PREFIX)
cache2go.RemPrefixKey(utils.RATING_PLAN_PREFIX)
} else if len(rpKeys) != 0 {
Logger.Info(fmt.Sprintf("Caching rating plans: %v", rpKeys))
}
for _, key := range rpKeys {
cache2go.RemKey(key)
if _, err = rs.GetRatingPlan(key[len(RATING_PLAN_PREFIX):], true); err != nil {
if _, err = rs.GetRatingPlan(key[len(utils.RATING_PLAN_PREFIX):], true); err != nil {
cache2go.RollbackTransaction()
return err
}
@@ -115,17 +161,17 @@ func (rs *RedisStorage) CacheRating(dKeys, rpKeys, rpfKeys, alsKeys, lcrKeys, dc
}
if rpfKeys == nil {
Logger.Info("Caching all rating profiles")
if rpfKeys, err = rs.db.Keys(RATING_PROFILE_PREFIX + "*"); err != nil {
if rpfKeys, err = rs.db.Keys(utils.RATING_PROFILE_PREFIX + "*"); err != nil {
cache2go.RollbackTransaction()
return err
}
cache2go.RemPrefixKey(RATING_PROFILE_PREFIX)
cache2go.RemPrefixKey(utils.RATING_PROFILE_PREFIX)
} else if len(rpfKeys) != 0 {
Logger.Info(fmt.Sprintf("Caching rating profile: %v", rpfKeys))
}
for _, key := range rpfKeys {
cache2go.RemKey(key)
if _, err = rs.GetRatingProfile(key[len(RATING_PROFILE_PREFIX):], true); err != nil {
if _, err = rs.GetRatingProfile(key[len(utils.RATING_PROFILE_PREFIX):], true); err != nil {
cache2go.RollbackTransaction()
return err
}
@@ -135,17 +181,17 @@ func (rs *RedisStorage) CacheRating(dKeys, rpKeys, rpfKeys, alsKeys, lcrKeys, dc
}
if lcrKeys == nil {
Logger.Info("Caching LCR rules.")
if lcrKeys, err = rs.db.Keys(LCR_PREFIX + "*"); err != nil {
if lcrKeys, err = rs.db.Keys(utils.LCR_PREFIX + "*"); err != nil {
cache2go.RollbackTransaction()
return err
}
cache2go.RemPrefixKey(LCR_PREFIX)
cache2go.RemPrefixKey(utils.LCR_PREFIX)
} else if len(lcrKeys) != 0 {
Logger.Info(fmt.Sprintf("Caching LCR rules: %v", lcrKeys))
}
for _, key := range lcrKeys {
cache2go.RemKey(key)
if _, err = rs.GetLCR(key[len(LCR_PREFIX):], true); err != nil {
if _, err = rs.GetLCR(key[len(utils.LCR_PREFIX):], true); err != nil {
cache2go.RollbackTransaction()
return err
}
@@ -153,40 +199,40 @@ func (rs *RedisStorage) CacheRating(dKeys, rpKeys, rpfKeys, alsKeys, lcrKeys, dc
if len(lcrKeys) != 0 {
Logger.Info("Finished LCR rules caching.")
}
if alsKeys == nil {
if plsKeys == nil {
Logger.Info("Caching all rating subject aliases.")
if alsKeys, err = rs.db.Keys(RP_ALIAS_PREFIX + "*"); err != nil {
if plsKeys, err = rs.db.Keys(utils.RP_ALIAS_PREFIX + "*"); err != nil {
cache2go.RollbackTransaction()
return err
}
cache2go.RemPrefixKey(RP_ALIAS_PREFIX)
} else if len(alsKeys) != 0 {
Logger.Info(fmt.Sprintf("Caching rating subject aliases: %v", alsKeys))
cache2go.RemPrefixKey(utils.RP_ALIAS_PREFIX)
} else if len(plsKeys) != 0 {
Logger.Info(fmt.Sprintf("Caching rating subject aliases: %v", plsKeys))
}
for _, key := range alsKeys {
for _, key := range plsKeys {
cache2go.RemKey(key)
if _, err = rs.GetRpAlias(key[len(RP_ALIAS_PREFIX):], true); err != nil {
if _, err = rs.GetRpAlias(key[len(utils.RP_ALIAS_PREFIX):], true); err != nil {
cache2go.RollbackTransaction()
return err
}
}
if len(alsKeys) != 0 {
if len(plsKeys) != 0 {
Logger.Info("Finished rating profile aliases caching.")
}
// DerivedChargers caching
if dcsKeys == nil {
Logger.Info("Caching all derived chargers")
if dcsKeys, err = rs.db.Keys(DERIVEDCHARGERS_PREFIX + "*"); err != nil {
if dcsKeys, err = rs.db.Keys(utils.DERIVEDCHARGERS_PREFIX + "*"); err != nil {
cache2go.RollbackTransaction()
return err
}
cache2go.RemPrefixKey(DERIVEDCHARGERS_PREFIX)
cache2go.RemPrefixKey(utils.DERIVEDCHARGERS_PREFIX)
} else if len(dcsKeys) != 0 {
Logger.Info(fmt.Sprintf("Caching derived chargers: %v", dcsKeys))
}
for _, key := range dcsKeys {
cache2go.RemKey(key)
if _, err = rs.GetDerivedChargers(key[len(DERIVEDCHARGERS_PREFIX):], true); err != nil {
if _, err = rs.GetDerivedChargers(key[len(utils.DERIVEDCHARGERS_PREFIX):], true); err != nil {
cache2go.RollbackTransaction()
return err
}
@@ -194,18 +240,12 @@ func (rs *RedisStorage) CacheRating(dKeys, rpKeys, rpfKeys, alsKeys, lcrKeys, dc
if len(dcsKeys) != 0 {
Logger.Info("Finished derived chargers caching.")
}
cache2go.CommitTransaction()
return nil
}
func (rs *RedisStorage) CacheAccounting(actKeys, shgKeys, alsKeys []string) (err error) {
cache2go.BeginTransaction()
if actKeys == nil {
cache2go.RemPrefixKey(ACTION_PREFIX)
cache2go.RemPrefixKey(utils.ACTION_PREFIX)
}
if actKeys == nil {
Logger.Info("Caching all actions")
if actKeys, err = rs.db.Keys(ACTION_PREFIX + "*"); err != nil {
if actKeys, err = rs.db.Keys(utils.ACTION_PREFIX + "*"); err != nil {
cache2go.RollbackTransaction()
return err
}
@@ -214,7 +254,7 @@ func (rs *RedisStorage) CacheAccounting(actKeys, shgKeys, alsKeys []string) (err
}
for _, key := range actKeys {
cache2go.RemKey(key)
if _, err = rs.GetActions(key[len(ACTION_PREFIX):], true); err != nil {
if _, err = rs.GetActions(key[len(utils.ACTION_PREFIX):], true); err != nil {
cache2go.RollbackTransaction()
return err
}
@@ -223,11 +263,11 @@ func (rs *RedisStorage) CacheAccounting(actKeys, shgKeys, alsKeys []string) (err
Logger.Info("Finished actions caching.")
}
if shgKeys == nil {
cache2go.RemPrefixKey(SHARED_GROUP_PREFIX)
cache2go.RemPrefixKey(utils.SHARED_GROUP_PREFIX)
}
if shgKeys == nil {
Logger.Info("Caching all shared groups")
if shgKeys, err = rs.db.Keys(SHARED_GROUP_PREFIX + "*"); err != nil {
if shgKeys, err = rs.db.Keys(utils.SHARED_GROUP_PREFIX + "*"); err != nil {
cache2go.RollbackTransaction()
return err
}
@@ -236,7 +276,7 @@ func (rs *RedisStorage) CacheAccounting(actKeys, shgKeys, alsKeys []string) (err
}
for _, key := range shgKeys {
cache2go.RemKey(key)
if _, err = rs.GetSharedGroup(key[len(SHARED_GROUP_PREFIX):], true); err != nil {
if _, err = rs.GetSharedGroup(key[len(utils.SHARED_GROUP_PREFIX):], true); err != nil {
cache2go.RollbackTransaction()
return err
}
@@ -246,17 +286,17 @@ func (rs *RedisStorage) CacheAccounting(actKeys, shgKeys, alsKeys []string) (err
}
if alsKeys == nil {
Logger.Info("Caching all account aliases.")
if alsKeys, err = rs.db.Keys(ACC_ALIAS_PREFIX + "*"); err != nil {
if alsKeys, err = rs.db.Keys(utils.ACC_ALIAS_PREFIX + "*"); err != nil {
cache2go.RollbackTransaction()
return err
}
cache2go.RemPrefixKey(ACC_ALIAS_PREFIX)
cache2go.RemPrefixKey(utils.ACC_ALIAS_PREFIX)
} else if len(alsKeys) != 0 {
Logger.Info(fmt.Sprintf("Caching account aliases: %v", alsKeys))
}
for _, key := range alsKeys {
cache2go.RemKey(key)
if _, err = rs.GetAccAlias(key[len(ACC_ALIAS_PREFIX):], true); err != nil {
if _, err = rs.GetAccAlias(key[len(utils.ACC_ALIAS_PREFIX):], true); err != nil {
cache2go.RollbackTransaction()
return err
}
@@ -271,14 +311,14 @@ func (rs *RedisStorage) CacheAccounting(actKeys, shgKeys, alsKeys []string) (err
// Used to check if specific subject is stored using prefix key attached to entity
func (rs *RedisStorage) HasData(category, subject string) (bool, error) {
switch category {
case DESTINATION_PREFIX, RATING_PLAN_PREFIX, RATING_PROFILE_PREFIX, ACTION_PREFIX, ACTION_TIMING_PREFIX, ACCOUNT_PREFIX:
case utils.DESTINATION_PREFIX, utils.RATING_PLAN_PREFIX, utils.RATING_PROFILE_PREFIX, utils.ACTION_PREFIX, utils.ACTION_TIMING_PREFIX, utils.ACCOUNT_PREFIX:
return rs.db.Exists(category + subject)
}
return false, errors.New("Unsupported category in HasData")
}
func (rs *RedisStorage) GetRatingPlan(key string, skipCache bool) (rp *RatingPlan, err error) {
key = RATING_PLAN_PREFIX + key
key = utils.RATING_PLAN_PREFIX + key
if !skipCache {
if x, err := cache2go.GetCached(key); err == nil {
return x.(*RatingPlan), nil
@@ -311,18 +351,18 @@ func (rs *RedisStorage) SetRatingPlan(rp *RatingPlan) (err error) {
w := zlib.NewWriter(&b)
w.Write(result)
w.Close()
err = rs.db.Set(RATING_PLAN_PREFIX+rp.Id, b.Bytes())
err = rs.db.Set(utils.RATING_PLAN_PREFIX+rp.Id, b.Bytes())
if err == nil && historyScribe != nil {
response := 0
go historyScribe.Record(rp.GetHistoryRecord(), &response)
}
//cache2go.Cache(RATING_PLAN_PREFIX+rp.Id, rp)
//cache2go.Cache(utils.RATING_PLAN_PREFIX+rp.Id, rp)
return
}
func (rs *RedisStorage) GetRatingProfile(key string, skipCache bool) (rpf *RatingProfile, err error) {
key = RATING_PROFILE_PREFIX + key
key = utils.RATING_PROFILE_PREFIX + key
if !skipCache {
if x, err := cache2go.GetCached(key); err == nil {
return x.(*RatingProfile), nil
@@ -341,17 +381,17 @@ func (rs *RedisStorage) GetRatingProfile(key string, skipCache bool) (rpf *Ratin
func (rs *RedisStorage) SetRatingProfile(rpf *RatingProfile) (err error) {
result, err := rs.ms.Marshal(rpf)
err = rs.db.Set(RATING_PROFILE_PREFIX+rpf.Id, result)
err = rs.db.Set(utils.RATING_PROFILE_PREFIX+rpf.Id, result)
if err == nil && historyScribe != nil {
response := 0
go historyScribe.Record(rpf.GetHistoryRecord(), &response)
}
//cache2go.Cache(RATING_PROFILE_PREFIX+rpf.Id, rpf)
//cache2go.Cache(utils.RATING_PROFILE_PREFIX+rpf.Id, rpf)
return
}
func (rs *RedisStorage) GetRpAlias(key string, skipCache bool) (alias string, err error) {
key = RP_ALIAS_PREFIX + key
key = utils.RP_ALIAS_PREFIX + key
if !skipCache {
if x, err := cache2go.GetCached(key); err == nil {
return x.(string), nil
@@ -368,23 +408,23 @@ func (rs *RedisStorage) GetRpAlias(key string, skipCache bool) (alias string, er
}
func (rs *RedisStorage) SetRpAlias(key, alias string) (err error) {
err = rs.db.Set(RP_ALIAS_PREFIX+key, []byte(alias))
err = rs.db.Set(utils.RP_ALIAS_PREFIX+key, []byte(alias))
return
}
// Removes the aliases of a specific account, on a tenant
func (rs *RedisStorage) RemoveRpAliases(tenantRtSubjects []*TenantRatingSubject) (err error) {
alsKeys, err := rs.db.Keys(RP_ALIAS_PREFIX + "*")
alsKeys, err := rs.db.Keys(utils.RP_ALIAS_PREFIX + "*")
if err != nil {
return err
}
for _, key := range alsKeys {
alias, err := rs.GetRpAlias(key[len(RP_ALIAS_PREFIX):], true)
alias, err := rs.GetRpAlias(key[len(utils.RP_ALIAS_PREFIX):], true)
if err != nil {
return err
}
for _, tntRSubj := range tenantRtSubjects {
tenantPrfx := RP_ALIAS_PREFIX + tntRSubj.Tenant + utils.CONCATENATED_KEY_SEP
tenantPrfx := utils.RP_ALIAS_PREFIX + tntRSubj.Tenant + utils.CONCATENATED_KEY_SEP
if len(key) < len(tenantPrfx) || tenantPrfx != key[:len(tenantPrfx)] { // filter out the tenant for accounts
continue
}
@@ -402,7 +442,7 @@ func (rs *RedisStorage) RemoveRpAliases(tenantRtSubjects []*TenantRatingSubject)
}
func (rs *RedisStorage) GetRPAliases(tenant, subject string, skipCache bool) (aliases []string, err error) {
tenantPrfx := RP_ALIAS_PREFIX + tenant + utils.CONCATENATED_KEY_SEP
tenantPrfx := utils.RP_ALIAS_PREFIX + tenant + utils.CONCATENATED_KEY_SEP
var alsKeys []string
if !skipCache {
alsKeys = cache2go.GetEntriesKeys(tenantPrfx)
@@ -413,7 +453,7 @@ func (rs *RedisStorage) GetRPAliases(tenant, subject string, skipCache bool) (al
}
}
for _, key := range alsKeys {
if alsSubj, err := rs.GetRpAlias(key[len(RP_ALIAS_PREFIX):], skipCache); err != nil {
if alsSubj, err := rs.GetRpAlias(key[len(utils.RP_ALIAS_PREFIX):], skipCache); err != nil {
return nil, err
} else if alsSubj == subject {
alsFromKey := key[len(tenantPrfx):] // take out the alias out of key+tenant
@@ -424,7 +464,7 @@ func (rs *RedisStorage) GetRPAliases(tenant, subject string, skipCache bool) (al
}
func (rs *RedisStorage) GetLCR(key string, skipCache bool) (lcr *LCR, err error) {
key = LCR_PREFIX + key
key = utils.LCR_PREFIX + key
if !skipCache {
if x, err := cache2go.GetCached(key); err == nil {
return x.(*LCR), nil
@@ -442,13 +482,13 @@ func (rs *RedisStorage) GetLCR(key string, skipCache bool) (lcr *LCR, err error)
func (rs *RedisStorage) SetLCR(lcr *LCR) (err error) {
result, err := rs.ms.Marshal(lcr)
err = rs.db.Set(LCR_PREFIX+lcr.GetId(), result)
cache2go.Cache(LCR_PREFIX+lcr.GetId(), lcr)
err = rs.db.Set(utils.LCR_PREFIX+lcr.GetId(), result)
cache2go.Cache(utils.LCR_PREFIX+lcr.GetId(), lcr)
return
}
func (rs *RedisStorage) GetAccAlias(key string, skipCache bool) (alias string, err error) {
key = ACC_ALIAS_PREFIX + key
key = utils.ACC_ALIAS_PREFIX + key
if !skipCache {
if x, err := cache2go.GetCached(key); err == nil {
return x.(string), nil
@@ -466,23 +506,23 @@ func (rs *RedisStorage) GetAccAlias(key string, skipCache bool) (alias string, e
// Adds one alias for one account
func (rs *RedisStorage) SetAccAlias(key, alias string) (err error) {
err = rs.db.Set(ACC_ALIAS_PREFIX+key, []byte(alias))
err = rs.db.Set(utils.ACC_ALIAS_PREFIX+key, []byte(alias))
//cache2go.Cache(ALIAS_PREFIX+key, alias)
return
}
func (rs *RedisStorage) RemoveAccAliases(tenantAccounts []*TenantAccount) (err error) {
alsKeys, err := rs.db.Keys(ACC_ALIAS_PREFIX + "*")
alsKeys, err := rs.db.Keys(utils.ACC_ALIAS_PREFIX + "*")
if err != nil {
return err
}
for _, key := range alsKeys {
alias, err := rs.GetAccAlias(key[len(ACC_ALIAS_PREFIX):], true)
alias, err := rs.GetAccAlias(key[len(utils.ACC_ALIAS_PREFIX):], true)
if err != nil {
return err
}
for _, tntAcnt := range tenantAccounts {
tenantPrfx := ACC_ALIAS_PREFIX + tntAcnt.Tenant + utils.CONCATENATED_KEY_SEP
tenantPrfx := utils.ACC_ALIAS_PREFIX + tntAcnt.Tenant + utils.CONCATENATED_KEY_SEP
if len(key) < len(tenantPrfx) || tenantPrfx != key[:len(tenantPrfx)] { // filter out the tenant for accounts
continue
}
@@ -500,7 +540,7 @@ func (rs *RedisStorage) RemoveAccAliases(tenantAccounts []*TenantAccount) (err e
// Returns the aliases of one specific account on a tenant
func (rs *RedisStorage) GetAccountAliases(tenant, account string, skipCache bool) (aliases []string, err error) {
tenantPrfx := ACC_ALIAS_PREFIX + tenant + utils.CONCATENATED_KEY_SEP
tenantPrfx := utils.ACC_ALIAS_PREFIX + tenant + utils.CONCATENATED_KEY_SEP
var alsKeys []string
if !skipCache {
alsKeys = cache2go.GetEntriesKeys(tenantPrfx)
@@ -511,7 +551,7 @@ func (rs *RedisStorage) GetAccountAliases(tenant, account string, skipCache bool
}
}
for _, key := range alsKeys {
if alsAcnt, err := rs.GetAccAlias(key[len(ACC_ALIAS_PREFIX):], skipCache); err != nil {
if alsAcnt, err := rs.GetAccAlias(key[len(utils.ACC_ALIAS_PREFIX):], skipCache); err != nil {
return nil, err
} else if alsAcnt == account {
alsFromKey := key[len(tenantPrfx):] // take out the alias out of key+tenant
@@ -522,7 +562,7 @@ func (rs *RedisStorage) GetAccountAliases(tenant, account string, skipCache bool
}
func (rs *RedisStorage) GetDestination(key string) (dest *Destination, err error) {
key = DESTINATION_PREFIX + key
key = utils.DESTINATION_PREFIX + key
var values []byte
if values, err = rs.db.Get(key); len(values) > 0 && err == nil {
b := bytes.NewBuffer(values)
@@ -539,7 +579,7 @@ func (rs *RedisStorage) GetDestination(key string) (dest *Destination, err error
err = rs.ms.Unmarshal(out, dest)
// create optimized structure
for _, p := range dest.Prefixes {
cache2go.CachePush(DESTINATION_PREFIX+p, dest.Id)
cache2go.CachePush(utils.DESTINATION_PREFIX+p, dest.Id)
}
} else {
return nil, errors.New("not found")
@@ -556,17 +596,17 @@ func (rs *RedisStorage) SetDestination(dest *Destination) (err error) {
w := zlib.NewWriter(&b)
w.Write(result)
w.Close()
err = rs.db.Set(DESTINATION_PREFIX+dest.Id, b.Bytes())
err = rs.db.Set(utils.DESTINATION_PREFIX+dest.Id, b.Bytes())
if err == nil && historyScribe != nil {
response := 0
go historyScribe.Record(dest.GetHistoryRecord(), &response)
}
//cache2go.Cache(DESTINATION_PREFIX+dest.Id, dest)
//cache2go.Cache(utils.DESTINATION_PREFIX+dest.Id, dest)
return
}
func (rs *RedisStorage) GetActions(key string, skipCache bool) (as Actions, err error) {
key = ACTION_PREFIX + key
key = utils.ACTION_PREFIX + key
if !skipCache {
if x, err := cache2go.GetCached(key); err == nil {
return x.(Actions), nil
@@ -584,13 +624,13 @@ func (rs *RedisStorage) GetActions(key string, skipCache bool) (as Actions, err
func (rs *RedisStorage) SetActions(key string, as Actions) (err error) {
result, err := rs.ms.Marshal(&as)
err = rs.db.Set(ACTION_PREFIX+key, result)
// cache2go.Cache(ACTION_PREFIX+key, as)
err = rs.db.Set(utils.ACTION_PREFIX+key, result)
// cache2go.Cache(utils.ACTION_PREFIX+key, as)
return
}
func (rs *RedisStorage) GetSharedGroup(key string, skipCache bool) (sg *SharedGroup, err error) {
key = SHARED_GROUP_PREFIX + key
key = utils.SHARED_GROUP_PREFIX + key
if !skipCache {
if x, err := cache2go.GetCached(key); err == nil {
return x.(*SharedGroup), nil
@@ -608,14 +648,14 @@ func (rs *RedisStorage) GetSharedGroup(key string, skipCache bool) (sg *SharedGr
func (rs *RedisStorage) SetSharedGroup(sg *SharedGroup) (err error) {
result, err := rs.ms.Marshal(sg)
err = rs.db.Set(SHARED_GROUP_PREFIX+sg.Id, result)
//cache2go.Cache(SHARED_GROUP_PREFIX+sg.Id, sg)
err = rs.db.Set(utils.SHARED_GROUP_PREFIX+sg.Id, result)
//cache2go.Cache(utils.SHARED_GROUP_PREFIX+sg.Id, sg)
return
}
func (rs *RedisStorage) GetAccount(key string) (ub *Account, err error) {
var values []byte
if values, err = rs.db.Get(ACCOUNT_PREFIX + key); err == nil {
if values, err = rs.db.Get(utils.ACCOUNT_PREFIX + key); err == nil {
ub = &Account{Id: key}
err = rs.ms.Unmarshal(values, ub)
}
@@ -637,13 +677,13 @@ func (rs *RedisStorage) SetAccount(ub *Account) (err error) {
}
}
result, err := rs.ms.Marshal(ub)
err = rs.db.Set(ACCOUNT_PREFIX+ub.Id, result)
err = rs.db.Set(utils.ACCOUNT_PREFIX+ub.Id, result)
return
}
func (rs *RedisStorage) GetActionPlans(key string) (ats ActionPlans, err error) {
var values []byte
if values, err = rs.db.Get(ACTION_TIMING_PREFIX + key); err == nil {
if values, err = rs.db.Get(utils.ACTION_TIMING_PREFIX + key); err == nil {
err = rs.ms.Unmarshal(values, &ats)
}
return
@@ -652,16 +692,16 @@ func (rs *RedisStorage) GetActionPlans(key string) (ats ActionPlans, err error)
func (rs *RedisStorage) SetActionPlans(key string, ats ActionPlans) (err error) {
if len(ats) == 0 {
// delete the key
_, err = rs.db.Del(ACTION_TIMING_PREFIX + key)
_, err = rs.db.Del(utils.ACTION_TIMING_PREFIX + key)
return err
}
result, err := rs.ms.Marshal(&ats)
err = rs.db.Set(ACTION_TIMING_PREFIX+key, result)
err = rs.db.Set(utils.ACTION_TIMING_PREFIX+key, result)
return
}
func (rs *RedisStorage) GetAllActionPlans() (ats map[string]ActionPlans, err error) {
keys, err := rs.db.Keys(ACTION_TIMING_PREFIX + "*")
keys, err := rs.db.Keys(utils.ACTION_TIMING_PREFIX + "*")
if err != nil {
return nil, err
}
@@ -673,14 +713,14 @@ func (rs *RedisStorage) GetAllActionPlans() (ats map[string]ActionPlans, err err
}
var tempAts ActionPlans
err = rs.ms.Unmarshal(values, &tempAts)
ats[key[len(ACTION_TIMING_PREFIX):]] = tempAts
ats[key[len(utils.ACTION_TIMING_PREFIX):]] = tempAts
}
return
}
func (rs *RedisStorage) GetDerivedChargers(key string, skipCache bool) (dcs utils.DerivedChargers, err error) {
key = DERIVEDCHARGERS_PREFIX + key
key = utils.DERIVEDCHARGERS_PREFIX + key
if !skipCache {
if x, err := cache2go.GetCached(key); err == nil {
return x.(utils.DerivedChargers), nil
@@ -698,31 +738,31 @@ func (rs *RedisStorage) GetDerivedChargers(key string, skipCache bool) (dcs util
func (rs *RedisStorage) SetDerivedChargers(key string, dcs utils.DerivedChargers) (err error) {
if len(dcs) == 0 {
_, err = rs.db.Del(DERIVEDCHARGERS_PREFIX + key)
_, err = rs.db.Del(utils.DERIVEDCHARGERS_PREFIX + key)
// FIXME: Does cache need cleanup too?
return err
}
marshaled, err := rs.ms.Marshal(dcs)
err = rs.db.Set(DERIVEDCHARGERS_PREFIX+key, marshaled)
err = rs.db.Set(utils.DERIVEDCHARGERS_PREFIX+key, marshaled)
return err
}
func (rs *RedisStorage) SetCdrStats(cs *CdrStats) error {
marshaled, err := rs.ms.Marshal(cs)
err = rs.db.Set(CDR_STATS_PREFIX+cs.Id, marshaled)
err = rs.db.Set(utils.CDR_STATS_PREFIX+cs.Id, marshaled)
return err
}
func (rs *RedisStorage) GetCdrStats(key string) (cs *CdrStats, err error) {
var values []byte
if values, err = rs.db.Get(CDR_STATS_PREFIX + key); err == nil {
if values, err = rs.db.Get(utils.CDR_STATS_PREFIX + key); err == nil {
err = rs.ms.Unmarshal(values, &cs)
}
return
}
func (rs *RedisStorage) GetAllCdrStats() (css []*CdrStats, err error) {
keys, err := rs.db.Keys(CDR_STATS_PREFIX + "*")
keys, err := rs.db.Keys(utils.CDR_STATS_PREFIX + "*")
if err != nil {
return nil, err
}
@@ -744,13 +784,13 @@ func (rs *RedisStorage) LogCallCost(cgrid, source, runid string, cc *CallCost) (
if err != nil {
return
}
err = rs.db.Set(LOG_CALL_COST_PREFIX+source+runid+"_"+cgrid, result)
err = rs.db.Set(utils.LOG_CALL_COST_PREFIX+source+runid+"_"+cgrid, result)
return
}
func (rs *RedisStorage) GetCallCostLog(cgrid, source, runid string) (cc *CallCost, err error) {
var values []byte
if values, err = rs.db.Get(LOG_CALL_COST_PREFIX + source + runid + "_" + cgrid); err == nil {
if values, err = rs.db.Get(utils.LOG_CALL_COST_PREFIX + source + runid + "_" + cgrid); err == nil {
err = rs.ms.Unmarshal(values, cc)
}
return
@@ -765,7 +805,7 @@ func (rs *RedisStorage) LogActionTrigger(ubId, source string, at *ActionTrigger,
if err != nil {
return
}
rs.db.Set(LOG_ACTION_TRIGGER_PREFIX+source+"_"+time.Now().Format(time.RFC3339Nano), []byte(fmt.Sprintf("%v*%v*%v", ubId, string(mat), string(mas))))
rs.db.Set(utils.LOG_ACTION_TRIGGER_PREFIX+source+"_"+time.Now().Format(time.RFC3339Nano), []byte(fmt.Sprintf("%v*%v*%v", ubId, string(mat), string(mas))))
return
}
@@ -778,11 +818,12 @@ func (rs *RedisStorage) LogActionPlan(source string, at *ActionPlan, as Actions)
if err != nil {
return
}
err = rs.db.Set(LOG_ACTION_TIMMING_PREFIX+source+"_"+time.Now().Format(time.RFC3339Nano), []byte(fmt.Sprintf("%v*%v", string(mat), string(mas))))
err = rs.db.Set(utils.LOG_ACTION_TIMMING_PREFIX+source+"_"+time.Now().Format(time.RFC3339Nano), []byte(fmt.Sprintf("%v*%v", string(mat), string(mas))))
return
}
func (rs *RedisStorage) LogError(uuid, source, runid, errstr string) (err error) {
err = rs.db.Set(LOG_ERR+source+runid+"_"+uuid, []byte(errstr))
err = rs.db.Set(utils.
LOG_ERR+source+runid+"_"+uuid, []byte(errstr))
return
}

View File

@@ -48,7 +48,7 @@ func TestFlush(t *testing.T) {
if err := rds.Flush(""); err != nil {
t.Error("Failed to Flush redis database", err.Error())
}
rds.CacheRating(nil, nil, nil, nil, nil, nil)
rds.CacheAll()
}
func TestSetGetDerivedCharges(t *testing.T) {

View File

@@ -105,7 +105,7 @@ func TestCacheRefresh(t *testing.T) {
ratingStorage.GetDestination("T11")
ratingStorage.SetDestination(&Destination{"T11", []string{"1"}})
t.Log("Test cache refresh")
ratingStorage.CacheRating(nil, nil, nil, nil, nil, nil)
ratingStorage.CacheAll()
d, err := ratingStorage.GetDestination("T11")
p := d.containsPrefix("1")
if err != nil || p == 0 {
@@ -114,7 +114,7 @@ func TestCacheRefresh(t *testing.T) {
}
func TestCacheAliases(t *testing.T) {
if subj, err := cache2go.GetCached(RP_ALIAS_PREFIX + utils.RatingSubjectAliasKey("vdf", "a3")); err == nil && subj != "minu" {
if subj, err := cache2go.GetCached(utils.RP_ALIAS_PREFIX + utils.RatingSubjectAliasKey("vdf", "a3")); err == nil && subj != "minu" {
t.Error("Error caching alias: ", subj, err)
}
}
@@ -178,18 +178,18 @@ func TestRemRSubjAliases(t *testing.T) {
}
func TestGetAccountAliases(t *testing.T) {
if err := accountingStorage.SetAccAlias(utils.AccountAliasKey("cgrates.org", "2001"), "1001"); err != nil {
if err := ratingStorage.SetAccAlias(utils.AccountAliasKey("cgrates.org", "2001"), "1001"); err != nil {
t.Error(err)
}
if err := accountingStorage.SetAccAlias(utils.AccountAliasKey("cgrates.org", "2002"), "1001"); err != nil {
if err := ratingStorage.SetAccAlias(utils.AccountAliasKey("cgrates.org", "2002"), "1001"); err != nil {
t.Error(err)
}
if err := accountingStorage.SetAccAlias(utils.AccountAliasKey("itsyscom.com", "2003"), "1001"); err != nil {
if err := ratingStorage.SetAccAlias(utils.AccountAliasKey("itsyscom.com", "2003"), "1001"); err != nil {
t.Error(err)
}
expectAliases := sort.StringSlice([]string{"2001", "2002"})
expectAliases.Sort()
if aliases, err := accountingStorage.GetAccountAliases("cgrates.org", "1001", true); err != nil {
if aliases, err := ratingStorage.GetAccountAliases("cgrates.org", "1001", true); err != nil {
t.Error(err)
} else {
aliases := sort.StringSlice(aliases)

View File

@@ -159,7 +159,7 @@ func (tpr *TpReader) LoadDestinationRates() (err error) {
_, destinationExists = tpr.destinations[dr.DestinationId]
}
if !destinationExists && tpr.ratingStorage != nil {
if destinationExists, err = tpr.ratingStorage.HasData(DESTINATION_PREFIX, dr.DestinationId); err != nil {
if destinationExists, err = tpr.ratingStorage.HasData(utils.DESTINATION_PREFIX, dr.DestinationId); err != nil {
return err
}
}
@@ -228,7 +228,7 @@ func (tpr *TpReader) LoadRatingPlansFiltered(tag string) (bool, error) {
}
destsExist := len(dms) != 0
if !destsExist && tpr.ratingStorage != nil {
if dbExists, err := tpr.ratingStorage.HasData(DESTINATION_PREFIX, drate.DestinationId); err != nil {
if dbExists, err := tpr.ratingStorage.HasData(utils.DESTINATION_PREFIX, drate.DestinationId); err != nil {
return false, err
} else if dbExists {
destsExist = true
@@ -305,7 +305,7 @@ func (tpr *TpReader) LoadRatingProfilesFiltered(qriedRpf *TpRatingProfile) error
}
_, exists := tpr.ratingPlans[tpRa.RatingPlanId]
if !exists && tpr.ratingStorage != nil {
if exists, err = tpr.ratingStorage.HasData(RATING_PLAN_PREFIX, tpRa.RatingPlanId); err != nil {
if exists, err = tpr.ratingStorage.HasData(utils.RATING_PLAN_PREFIX, tpRa.RatingPlanId); err != nil {
return err
}
}
@@ -355,7 +355,7 @@ func (tpr *TpReader) LoadRatingProfiles() (err error) {
}
_, exists := tpr.ratingPlans[tpRa.RatingPlanId]
if !exists && tpr.ratingStorage != nil { // Only query if there is a connection, eg on dry run there is none
if exists, err = tpr.ratingStorage.HasData(RATING_PLAN_PREFIX, tpRa.RatingPlanId); err != nil {
if exists, err = tpr.ratingStorage.HasData(utils.RATING_PLAN_PREFIX, tpRa.RatingPlanId); err != nil {
return err
}
}
@@ -402,7 +402,7 @@ func (tpr *TpReader) LoadSharedGroupsFiltered(tag string, save bool) (err error)
}
if save {
for _, sg := range tpr.sharedGroups {
if err := tpr.accountingStorage.SetSharedGroup(sg); err != nil {
if err := tpr.ratingStorage.SetSharedGroup(sg); err != nil {
return err
}
}
@@ -431,7 +431,7 @@ func (tpr *TpReader) LoadLCRs() (err error) {
}
}
if !found && tpr.ratingStorage != nil {
if keys, err := tpr.ratingStorage.GetKeysForPrefix(RATING_PROFILE_PREFIX + ratingProfileSearchKey); err != nil {
if keys, err := tpr.ratingStorage.GetKeysForPrefix(utils.RATING_PROFILE_PREFIX + ratingProfileSearchKey); err != nil {
return fmt.Errorf("[LCR] error querying ratingDb %s", err.Error())
} else if len(keys) != 0 {
found = true
@@ -445,7 +445,7 @@ func (tpr *TpReader) LoadLCRs() (err error) {
if tpLcr.DestinationTag != "" && tpLcr.DestinationTag != utils.ANY {
_, found := tpr.destinations[tpLcr.DestinationTag]
if !found && tpr.ratingStorage != nil {
if found, err = tpr.ratingStorage.HasData(DESTINATION_PREFIX, tpLcr.DestinationTag); err != nil {
if found, err = tpr.ratingStorage.HasData(utils.DESTINATION_PREFIX, tpLcr.DestinationTag); err != nil {
return fmt.Errorf("[LCR] error querying ratingDb %s", err.Error())
}
}
@@ -564,7 +564,7 @@ func (tpr *TpReader) LoadActionPlans() (err error) {
_, exists := tpr.actions[at.ActionsId]
if !exists && tpr.ratingStorage != nil {
if exists, err = tpr.ratingStorage.HasData(ACTION_PREFIX, at.ActionsId); err != nil {
if exists, err = tpr.ratingStorage.HasData(utils.ACTION_PREFIX, at.ActionsId); err != nil {
return fmt.Errorf("[ActionPlans] Error querying actions: %v - %s", at.ActionsId, err.Error())
}
}
@@ -664,7 +664,7 @@ func (tpr *TpReader) LoadAccountActionsFiltered(qriedAA *TpAccountAction) error
if accountAction.ActionPlanId != "" {
// get old userBalanceIds
var exitingAccountIds []string
existingActionPlans, err := tpr.accountingStorage.GetActionPlans(accountAction.ActionPlanId)
existingActionPlans, err := tpr.ratingStorage.GetActionPlans(accountAction.ActionPlanId)
if err == nil && len(existingActionPlans) > 0 {
// all action timings from a specific tag shuld have the same list of user balances from the first one
exitingAccountIds = existingActionPlans[0].AccountIds
@@ -732,7 +732,7 @@ func (tpr *TpReader) LoadAccountActionsFiltered(qriedAA *TpAccountAction) error
}
// write action timings
err = tpr.accountingStorage.SetActionPlans(accountAction.ActionPlanId, actionTimings)
err = tpr.ratingStorage.SetActionPlans(accountAction.ActionPlanId, actionTimings)
if err != nil {
return errors.New(err.Error() + " (SetActionPlan): " + accountAction.ActionPlanId)
}
@@ -816,7 +816,7 @@ func (tpr *TpReader) LoadAccountActionsFiltered(qriedAA *TpAccountAction) error
}
// writee actions
for k, as := range acts {
err = tpr.accountingStorage.SetActions(k, as)
err = tpr.ratingStorage.SetActions(k, as)
if err != nil {
return err
}
@@ -1075,7 +1075,7 @@ func (tpr *TpReader) WriteToDatabase(flush, verbose bool) (err error) {
log.Print("Action Plans:")
}
for k, ats := range tpr.actionsTimings {
err = tpr.accountingStorage.SetActionPlans(k, ats)
err = tpr.ratingStorage.SetActionPlans(k, ats)
if err != nil {
return err
}
@@ -1087,7 +1087,7 @@ func (tpr *TpReader) WriteToDatabase(flush, verbose bool) (err error) {
log.Print("Shared Groups:")
}
for k, sg := range tpr.sharedGroups {
err = tpr.accountingStorage.SetSharedGroup(sg)
err = tpr.ratingStorage.SetSharedGroup(sg)
if err != nil {
return err
}
@@ -1111,7 +1111,7 @@ func (tpr *TpReader) WriteToDatabase(flush, verbose bool) (err error) {
log.Print("Actions:")
}
for k, as := range tpr.actions {
err = tpr.accountingStorage.SetActions(k, as)
err = tpr.ratingStorage.SetActions(k, as)
if err != nil {
return err
}
@@ -1149,11 +1149,11 @@ func (tpr *TpReader) WriteToDatabase(flush, verbose bool) (err error) {
if verbose {
log.Print("Account Aliases:")
}
if err := tpr.accountingStorage.RemoveAccAliases(tpr.dirtyAccAliases); err != nil {
if err := tpr.ratingStorage.RemoveAccAliases(tpr.dirtyAccAliases); err != nil {
return err
}
for key, alias := range tpr.accAliases {
err = tpr.accountingStorage.SetAccAlias(key, alias)
err = tpr.ratingStorage.SetAccAlias(key, alias)
if err != nil {
return err
}
@@ -1250,7 +1250,7 @@ func (tpr *TpReader) ShowStatistics() {
// Returns the identities loaded for a specific category, useful for cache reloads
func (tpr *TpReader) GetLoadedIds(categ string) ([]string, error) {
switch categ {
case DESTINATION_PREFIX:
case utils.DESTINATION_PREFIX:
keys := make([]string, len(tpr.destinations))
i := 0
for k := range tpr.destinations {
@@ -1258,7 +1258,7 @@ func (tpr *TpReader) GetLoadedIds(categ string) ([]string, error) {
i++
}
return keys, nil
case RATING_PLAN_PREFIX:
case utils.RATING_PLAN_PREFIX:
keys := make([]string, len(tpr.ratingPlans))
i := 0
for k := range tpr.ratingPlans {
@@ -1266,7 +1266,7 @@ func (tpr *TpReader) GetLoadedIds(categ string) ([]string, error) {
i++
}
return keys, nil
case RATING_PROFILE_PREFIX:
case utils.RATING_PROFILE_PREFIX:
keys := make([]string, len(tpr.ratingProfiles))
i := 0
for k := range tpr.ratingProfiles {
@@ -1274,7 +1274,7 @@ func (tpr *TpReader) GetLoadedIds(categ string) ([]string, error) {
i++
}
return keys, nil
case ACTION_PREFIX: // actionsTimings
case utils.ACTION_PREFIX: // actionsTimings
keys := make([]string, len(tpr.actions))
i := 0
for k := range tpr.actions {
@@ -1282,7 +1282,7 @@ func (tpr *TpReader) GetLoadedIds(categ string) ([]string, error) {
i++
}
return keys, nil
case ACTION_TIMING_PREFIX: // actionsTimings
case utils.ACTION_TIMING_PREFIX: // actionsTimings
keys := make([]string, len(tpr.actionsTimings))
i := 0
for k := range tpr.actionsTimings {
@@ -1290,7 +1290,7 @@ func (tpr *TpReader) GetLoadedIds(categ string) ([]string, error) {
i++
}
return keys, nil
case RP_ALIAS_PREFIX: // aliases
case utils.RP_ALIAS_PREFIX: // aliases
keys := make([]string, len(tpr.rpAliases))
i := 0
for k := range tpr.rpAliases {
@@ -1298,7 +1298,7 @@ func (tpr *TpReader) GetLoadedIds(categ string) ([]string, error) {
i++
}
return keys, nil
case ACC_ALIAS_PREFIX: // aliases
case utils.ACC_ALIAS_PREFIX: // aliases
keys := make([]string, len(tpr.accAliases))
i := 0
for k := range tpr.accAliases {
@@ -1306,7 +1306,7 @@ func (tpr *TpReader) GetLoadedIds(categ string) ([]string, error) {
i++
}
return keys, nil
case DERIVEDCHARGERS_PREFIX: // derived chargers
case utils.DERIVEDCHARGERS_PREFIX: // derived chargers
keys := make([]string, len(tpr.derivedChargers))
i := 0
for k := range tpr.derivedChargers {
@@ -1314,7 +1314,7 @@ func (tpr *TpReader) GetLoadedIds(categ string) ([]string, error) {
i++
}
return keys, nil
case CDR_STATS_PREFIX: // cdr stats
case utils.CDR_STATS_PREFIX: // cdr stats
keys := make([]string, len(tpr.cdrStats))
i := 0
for k := range tpr.cdrStats {
@@ -1322,7 +1322,7 @@ func (tpr *TpReader) GetLoadedIds(categ string) ([]string, error) {
i++
}
return keys, nil
case SHARED_GROUP_PREFIX:
case utils.SHARED_GROUP_PREFIX:
keys := make([]string, len(tpr.sharedGroups))
i := 0
for k := range tpr.sharedGroups {

View File

@@ -42,7 +42,7 @@ func (uc *UnitsCounter) initBalances(ats []*ActionTrigger) {
// only get actions fo counter type action triggers
continue
}
acs, err := accountingStorage.GetActions(at.ActionsId, false)
acs, err := ratingStorage.GetActions(at.ActionsId, false)
if err != nil {
continue
}
@@ -77,7 +77,7 @@ func (uc *UnitsCounter) addUnits(amount float64, prefix string) {
continue
}
for _, p := range utils.SplitPrefix(prefix, MIN_PREFIX_MATCH) {
if x, err := cache2go.GetCached(DESTINATION_PREFIX + p); err == nil {
if x, err := cache2go.GetCached(utils.DESTINATION_PREFIX + p); err == nil {
destIds := x.(map[interface{}]struct{})
if _, found := destIds[mb.DestinationIds]; found {
mb.Value += amount