func (cd *CallDescriptor) FlushCache() (err error) { cache.Flush() ratingStorage.PreloadRatingCache() accountingStorage.PreloadAccountingCache() return nil }
func TestSMSLoadCsvTpSmsChrg1(t *testing.T) { timings := `ALWAYS,*any,*any,*any,*any,00:00:00` rates := `RT_SMS_5c,0,0.005,1,1,0` destinationRates := `DR_SMS_1,*any,RT_SMS_5c,*up,4,0,` ratingPlans := `RP_SMS1,DR_SMS_1,ALWAYS,10` ratingProfiles := `*out,cgrates.org,sms,*any,2012-01-01T00:00:00Z,RP_SMS1,,` csvr := engine.NewTpReader(ratingDb, acntDb, engine.NewStringCSVStorage(',', "", timings, rates, destinationRates, ratingPlans, ratingProfiles, "", "", "", "", "", "", "", "", "", "", ""), "", "") if err := csvr.LoadTimings(); err != nil { t.Fatal(err) } if err := csvr.LoadRates(); err != nil { t.Fatal(err) } if err := csvr.LoadDestinationRates(); err != nil { t.Fatal(err) } if err := csvr.LoadRatingPlans(); err != nil { t.Fatal(err) } if err := csvr.LoadRatingProfiles(); err != nil { t.Fatal(err) } csvr.WriteToDatabase(false, false, false) cache.Flush() ratingDb.PreloadRatingCache() acntDb.PreloadAccountingCache() if cachedRPlans := cache.CountEntries(utils.RATING_PLAN_PREFIX); cachedRPlans != 1 { t.Error("Wrong number of cached rating plans found", cachedRPlans) } if cachedRProfiles := cache.CountEntries(utils.RATING_PROFILE_PREFIX); cachedRProfiles != 0 { t.Error("Wrong number of cached rating profiles found", cachedRProfiles) } }
func init() { csvr = NewTpReader(ratingStorage, accountingStorage, NewStringCSVStorage(',', destinations, timings, rates, destinationRates, ratingPlans, ratingProfiles, sharedGroups, lcrs, actions, actionPlans, actionTriggers, accountActions, derivedCharges, cdrStats, users, aliases, resLimits), testTPID, "") if err := csvr.LoadDestinations(); err != nil { log.Print("error in LoadDestinations:", err) } if err := csvr.LoadTimings(); err != nil { log.Print("error in LoadTimings:", err) } if err := csvr.LoadRates(); err != nil { log.Print("error in LoadRates:", err) } if err := csvr.LoadDestinationRates(); err != nil { log.Print("error in LoadDestRates:", err) } if err := csvr.LoadRatingPlans(); err != nil { log.Print("error in LoadRatingPlans:", err) } if err := csvr.LoadRatingProfiles(); err != nil { log.Print("error in LoadRatingProfiles:", err) } if err := csvr.LoadSharedGroups(); err != nil { log.Print("error in LoadSharedGroups:", err) } if err := csvr.LoadLCRs(); err != nil { log.Print("error in LoadLCR:", err) } if err := csvr.LoadActions(); err != nil { log.Print("error in LoadActions:", err) } if err := csvr.LoadActionPlans(); err != nil { log.Print("error in LoadActionPlans:", err) } if err := csvr.LoadActionTriggers(); err != nil { log.Print("error in LoadActionTriggers:", err) } if err := csvr.LoadAccountActions(); err != nil { log.Print("error in LoadAccountActions:", err) } if err := csvr.LoadDerivedChargers(); err != nil { log.Print("error in LoadDerivedChargers:", err) } if err := csvr.LoadCdrStats(); err != nil { log.Print("error in LoadCdrStats:", err) } if err := csvr.LoadUsers(); err != nil { log.Print("error in LoadUsers:", err) } if err := csvr.LoadAliases(); err != nil { log.Print("error in LoadAliases:", err) } if err := csvr.LoadResourceLimits(); err != nil { log.Print("error in LoadResourceLimits:", err) } csvr.WriteToDatabase(false, false, false) cache.Flush() ratingStorage.PreloadRatingCache() accountingStorage.PreloadAccountingCache() }
func TestCosts1LoadCsvTp(t *testing.T) { timings := `ALWAYS,*any,*any,*any,*any,00:00:00 ASAP,*any,*any,*any,*any,*asap` dests := `GERMANY,+49 GERMANY_MOBILE,+4915 GERMANY_MOBILE,+4916 GERMANY_MOBILE,+4917` rates := `RT_1CENT,0,1,1s,1s,0s RT_DATA_2c,0,0.002,10,10,0 RT_SMS_5c,0,0.005,1,1,0` destinationRates := `DR_RETAIL,GERMANY,RT_1CENT,*up,4,0, DR_RETAIL,GERMANY_MOBILE,RT_1CENT,*up,4,0, DR_DATA_1,*any,RT_DATA_2c,*up,4,0, DR_SMS_1,*any,RT_SMS_5c,*up,4,0,` ratingPlans := `RP_RETAIL,DR_RETAIL,ALWAYS,10 RP_DATA1,DR_DATA_1,ALWAYS,10 RP_SMS1,DR_SMS_1,ALWAYS,10` ratingProfiles := `*out,cgrates.org,call,*any,2012-01-01T00:00:00Z,RP_RETAIL,, *out,cgrates.org,data,*any,2012-01-01T00:00:00Z,RP_DATA1,, *out,cgrates.org,sms,*any,2012-01-01T00:00:00Z,RP_SMS1,,` csvr := engine.NewTpReader(ratingDb, acntDb, engine.NewStringCSVStorage(',', dests, timings, rates, destinationRates, ratingPlans, ratingProfiles, "", "", "", "", "", "", "", "", "", "", ""), "", "") if err := csvr.LoadTimings(); err != nil { t.Fatal(err) } if err := csvr.LoadDestinations(); err != nil { t.Fatal(err) } if err := csvr.LoadRates(); err != nil { t.Fatal(err) } if err := csvr.LoadDestinationRates(); err != nil { t.Fatal(err) } if err := csvr.LoadRatingPlans(); err != nil { t.Fatal(err) } if err := csvr.LoadRatingProfiles(); err != nil { t.Fatal(err) } csvr.WriteToDatabase(false, false, false) cache.Flush() ratingDb.PreloadRatingCache() acntDb.PreloadAccountingCache() if cachedRPlans := cache.CountEntries(utils.RATING_PLAN_PREFIX); cachedRPlans != 3 { t.Error("Wrong number of cached rating plans found", cachedRPlans) } if cachedRProfiles := cache.CountEntries(utils.RATING_PROFILE_PREFIX); cachedRProfiles != 0 { t.Error("Wrong number of cached rating profiles found", cachedRProfiles) } }
func TestAuthLoadCsv(t *testing.T) { timings := `` destinations := `DST_GERMANY_LANDLINE,49` rates := `RT_1CENTWITHCF,0.02,0.01,60s,60s,0s` destinationRates := `DR_GERMANY,DST_GERMANY_LANDLINE,RT_1CENTWITHCF,*up,8,, DR_ANY_1CNT,*any,RT_1CENTWITHCF,*up,8,,` ratingPlans := `RP_1,DR_GERMANY,*any,10 RP_ANY,DR_ANY_1CNT,*any,10` ratingProfiles := `*out,cgrates.org,call,testauthpostpaid1,2013-01-06T00:00:00Z,RP_1,, *out,cgrates.org,call,testauthpostpaid2,2013-01-06T00:00:00Z,RP_1,*any, *out,cgrates.org,call,*any,2013-01-06T00:00:00Z,RP_ANY,,` sharedGroups := `` lcrs := `` actions := `TOPUP10_AC,*topup_reset,,,,*monetary,*out,,*any,,,*unlimited,,0,10,false,false,10` actionPlans := `TOPUP10_AT,TOPUP10_AC,*asap,10` actionTriggers := `` accountActions := `cgrates.org,testauthpostpaid1,TOPUP10_AT,,,` derivedCharges := `` cdrStats := `` users := `` aliases := `` resLimits := `` csvr := engine.NewTpReader(ratingDbAuth, acntDbAuth, engine.NewStringCSVStorage(',', destinations, timings, rates, destinationRates, ratingPlans, ratingProfiles, sharedGroups, lcrs, actions, actionPlans, actionTriggers, accountActions, derivedCharges, cdrStats, users, aliases, resLimits), "", "") if err := csvr.LoadAll(); err != nil { t.Fatal(err) } csvr.WriteToDatabase(false, false, false) if acnt, err := acntDbAuth.GetAccount("cgrates.org:testauthpostpaid1"); err != nil { t.Error(err) } else if acnt == nil { t.Error("No account saved") } cache.Flush() ratingDbAuth.PreloadRatingCache() acntDbAuth.PreloadAccountingCache() if cachedDests := cache.CountEntries(utils.DESTINATION_PREFIX); cachedDests != 0 { t.Error("Wrong number of cached destinations found", cachedDests) } if cachedRPlans := cache.CountEntries(utils.RATING_PLAN_PREFIX); cachedRPlans != 2 { t.Error("Wrong number of cached rating plans found", cachedRPlans) } if cachedRProfiles := cache.CountEntries(utils.RATING_PROFILE_PREFIX); cachedRProfiles != 0 { t.Error("Wrong number of cached rating profiles found", cachedRProfiles) } if cachedActions := cache.CountEntries(utils.ACTION_PREFIX); cachedActions != 0 { t.Error("Wrong number of cached actions found", cachedActions) } }
func TestAcntActsLoadCsv(t *testing.T) { timings := `ASAP,*any,*any,*any,*any,*asap` destinations := `` rates := `` destinationRates := `` ratingPlans := `` ratingProfiles := `` sharedGroups := `` lcrs := `` actions := `TOPUP10_AC,*topup_reset,,,,*voice,*out,,*any,,,*unlimited,,10,10,false,false,10 DISABLE_ACNT,*disable_account,,,,,,,,,,,,,,false,false,10 ENABLE_ACNT,*enable_account,,,,,,,,,,,,,,false,false,10` actionPlans := `TOPUP10_AT,TOPUP10_AC,ASAP,10` actionTriggers := `` accountActions := `cgrates.org,1,TOPUP10_AT,,,` derivedCharges := `` cdrStats := `` users := `` aliases := `` resLimits := `` csvr := engine.NewTpReader(ratingDbAcntActs, acntDbAcntActs, engine.NewStringCSVStorage(',', destinations, timings, rates, destinationRates, ratingPlans, ratingProfiles, sharedGroups, lcrs, actions, actionPlans, actionTriggers, accountActions, derivedCharges, cdrStats, users, aliases, resLimits), "", "") if err := csvr.LoadAll(); err != nil { t.Fatal(err) } csvr.WriteToDatabase(false, false, false) cache.Flush() ratingDbAcntActs.PreloadRatingCache() acntDbAcntActs.PreloadAccountingCache() expectAcnt := &engine.Account{ID: "cgrates.org:1"} if acnt, err := acntDbAcntActs.GetAccount("cgrates.org:1"); err != nil { t.Error(err) } else if acnt == nil { t.Error("No account created") } else if !reflect.DeepEqual(expectAcnt.ActionTriggers, acnt.ActionTriggers) { t.Errorf("Expecting: %+v, received: %+v", expectAcnt, acnt) } }
func TestLoadCsvTp(t *testing.T) { timings := `ALWAYS,*any,*any,*any,*any,00:00:00 ASAP,*any,*any,*any,*any,*asap` destinations := `DST_UK_Mobile_BIG5,447596 DST_UK_Mobile_BIG5,447956` rates := `RT_UK_Mobile_BIG5_PKG,0.01,0,20s,20s,0s RT_UK_Mobile_BIG5,0.01,0.10,1s,1s,0s` destinationRates := `DR_UK_Mobile_BIG5_PKG,DST_UK_Mobile_BIG5,RT_UK_Mobile_BIG5_PKG,*up,8,0, DR_UK_Mobile_BIG5,DST_UK_Mobile_BIG5,RT_UK_Mobile_BIG5,*up,8,0,` ratingPlans := `RP_UK_Mobile_BIG5_PKG,DR_UK_Mobile_BIG5_PKG,ALWAYS,10 RP_UK,DR_UK_Mobile_BIG5,ALWAYS,10` ratingProfiles := `*out,cgrates.org,call,*any,2013-01-06T00:00:00Z,RP_UK,, *out,cgrates.org,call,discounted_minutes,2013-01-06T00:00:00Z,RP_UK_Mobile_BIG5_PKG,,` sharedGroups := `` lcrs := `` actions := `TOPUP10_AC,*topup_reset,,,,*monetary,*out,,*any,,,*unlimited,,10,10,false,false,10 TOPUP10_AC1,*topup_reset,,,,*voice,*out,,DST_UK_Mobile_BIG5,discounted_minutes,,*unlimited,,40,10,false,false,10` actionPlans := `TOPUP10_AT,TOPUP10_AC,ASAP,10 TOPUP10_AT,TOPUP10_AC1,ASAP,10` actionTriggers := `` accountActions := `cgrates.org,12344,TOPUP10_AT,,,` derivedCharges := `` cdrStats := `` users := `` aliases := `` resLimits := `` csvr := engine.NewTpReader(ratingDb, acntDb, engine.NewStringCSVStorage(',', destinations, timings, rates, destinationRates, ratingPlans, ratingProfiles, sharedGroups, lcrs, actions, actionPlans, actionTriggers, accountActions, derivedCharges, cdrStats, users, aliases, resLimits), "", "") if err := csvr.LoadDestinations(); err != nil { t.Fatal(err) } if err := csvr.LoadTimings(); err != nil { t.Fatal(err) } if err := csvr.LoadRates(); err != nil { t.Fatal(err) } if err := csvr.LoadDestinationRates(); err != nil { t.Fatal(err) } if err := csvr.LoadRatingPlans(); err != nil { t.Fatal(err) } if err := csvr.LoadRatingProfiles(); err != nil { t.Fatal(err) } if err := csvr.LoadSharedGroups(); err != nil { t.Fatal(err) } if err := csvr.LoadLCRs(); err != nil { t.Fatal(err) } if err := csvr.LoadActions(); err != nil { t.Fatal(err) } if err := csvr.LoadActionPlans(); err != nil { t.Fatal(err) } if err := csvr.LoadActionTriggers(); err != nil { t.Fatal(err) } if err := csvr.LoadAccountActions(); err != nil { t.Fatal(err) } if err := csvr.LoadDerivedChargers(); err != nil { t.Fatal(err) } csvr.WriteToDatabase(false, false, false) if acnt, err := acntDb.GetAccount("cgrates.org:12344"); err != nil { t.Error(err) } else if acnt == nil { t.Error("No account saved") } cache.Flush() ratingDb.PreloadRatingCache() acntDb.PreloadAccountingCache() if cachedDests := cache.CountEntries(utils.DESTINATION_PREFIX); cachedDests != 0 { t.Error("Wrong number of cached destinations found", cachedDests) } if cachedRPlans := cache.CountEntries(utils.RATING_PLAN_PREFIX); cachedRPlans != 2 { t.Error("Wrong number of cached rating plans found", cachedRPlans) } if cachedRProfiles := cache.CountEntries(utils.RATING_PROFILE_PREFIX); cachedRProfiles != 0 { t.Error("Wrong number of cached rating profiles found", cachedRProfiles) } if cachedActions := cache.CountEntries(utils.ACTION_PREFIX); cachedActions != 0 { t.Error("Wrong number of cached actions found", cachedActions) } }
func (self *ApierV1) LoadTariffPlanFromFolder(attrs utils.AttrLoadTpFromFolder, reply *string) error { if len(attrs.FolderPath) == 0 { return fmt.Errorf("%s:%s", utils.ErrMandatoryIeMissing.Error(), "FolderPath") } if fi, err := os.Stat(attrs.FolderPath); err != nil { if strings.HasSuffix(err.Error(), "no such file or directory") { return utils.ErrInvalidPath } return utils.NewErrServerError(err) } else if !fi.IsDir() { return utils.ErrInvalidPath } loader := engine.NewTpReader(self.RatingDb, self.AccountDb, engine.NewFileCSVStorage(utils.CSV_SEP, path.Join(attrs.FolderPath, utils.DESTINATIONS_CSV), path.Join(attrs.FolderPath, utils.TIMINGS_CSV), path.Join(attrs.FolderPath, utils.RATES_CSV), path.Join(attrs.FolderPath, utils.DESTINATION_RATES_CSV), path.Join(attrs.FolderPath, utils.RATING_PLANS_CSV), path.Join(attrs.FolderPath, utils.RATING_PROFILES_CSV), path.Join(attrs.FolderPath, utils.SHARED_GROUPS_CSV), path.Join(attrs.FolderPath, utils.LCRS_CSV), path.Join(attrs.FolderPath, utils.ACTIONS_CSV), path.Join(attrs.FolderPath, utils.ACTION_PLANS_CSV), path.Join(attrs.FolderPath, utils.ACTION_TRIGGERS_CSV), path.Join(attrs.FolderPath, utils.ACCOUNT_ACTIONS_CSV), path.Join(attrs.FolderPath, utils.DERIVED_CHARGERS_CSV), path.Join(attrs.FolderPath, utils.CDR_STATS_CSV), path.Join(attrs.FolderPath, utils.USERS_CSV), path.Join(attrs.FolderPath, utils.ALIASES_CSV), path.Join(attrs.FolderPath, utils.ResourceLimitsCsv), ), "", self.Config.DefaultTimezone) if err := loader.LoadAll(); err != nil { return utils.NewErrServerError(err) } if attrs.DryRun { *reply = OK return nil // Mission complete, no errors } if attrs.Validate { if !loader.IsValid() { *reply = OK return errors.New("invalid data") } } if err := loader.WriteToDatabase(attrs.FlushDb, false, false); err != nil { return utils.NewErrServerError(err) } // Make sure the items are in the cache dstIds, _ := loader.GetLoadedIds(utils.DESTINATION_PREFIX) dstKeys := make([]string, len(dstIds)) for idx, dId := range dstIds { dstKeys[idx] = utils.DESTINATION_PREFIX + dId // Cache expects them as redis keys } rplIds, _ := loader.GetLoadedIds(utils.RATING_PLAN_PREFIX) rpKeys := make([]string, len(rplIds)) for idx, rpId := range rplIds { rpKeys[idx] = utils.RATING_PLAN_PREFIX + rpId } rpfIds, _ := loader.GetLoadedIds(utils.RATING_PROFILE_PREFIX) rpfKeys := make([]string, len(rpfIds)) for idx, rpfId := range rpfIds { rpfKeys[idx] = utils.RATING_PROFILE_PREFIX + rpfId } actIds, _ := loader.GetLoadedIds(utils.ACTION_PREFIX) actKeys := make([]string, len(actIds)) for idx, actId := range actIds { actKeys[idx] = utils.ACTION_PREFIX + actId } aplIds, _ := loader.GetLoadedIds(utils.ACTION_PLAN_PREFIX) aplKeys := make([]string, len(aplIds)) for idx, aplId := range aplIds { aplKeys[idx] = utils.ACTION_PLAN_PREFIX + aplId } shgIds, _ := loader.GetLoadedIds(utils.SHARED_GROUP_PREFIX) shgKeys := make([]string, len(shgIds)) for idx, shgId := range shgIds { shgKeys[idx] = utils.SHARED_GROUP_PREFIX + shgId } aliases, _ := loader.GetLoadedIds(utils.ALIASES_PREFIX) alsKeys := make([]string, len(aliases)) for idx, alias := range aliases { alsKeys[idx] = utils.ALIASES_PREFIX + alias } lcrIds, _ := loader.GetLoadedIds(utils.LCR_PREFIX) lcrKeys := make([]string, len(lcrIds)) for idx, lcrId := range lcrIds { lcrKeys[idx] = utils.LCR_PREFIX + lcrId } dcs, _ := loader.GetLoadedIds(utils.DERIVEDCHARGERS_PREFIX) dcsKeys := make([]string, len(dcs)) for idx, dc := range dcs { dcsKeys[idx] = utils.DERIVEDCHARGERS_PREFIX + dc } aps, _ := loader.GetLoadedIds(utils.ACTION_PLAN_PREFIX) utils.Logger.Info("ApierV1.LoadTariffPlanFromFolder, reloading cache.") cstKeys, _ := loader.GetLoadedIds(utils.CDR_STATS_PREFIX) userKeys, _ := loader.GetLoadedIds(utils.USERS_PREFIX) // relase the tp data loader.Init() cache.Flush() self.RatingDb.PreloadRatingCache() self.AccountDb.PreloadAccountingCache() if len(aps) != 0 && self.Sched != nil { utils.Logger.Info("ApierV1.LoadTariffPlanFromFolder, reloading scheduler.") self.Sched.Reload(true) } if len(cstKeys) != 0 && self.CdrStatsSrv != nil { var out int if err := self.CdrStatsSrv.Call("CDRStatsV1.ReloadQueues", cstKeys, &out); err != nil { return err } } if len(userKeys) != 0 && self.Users != nil { var r string if err := self.Users.Call("UsersV1.ReloadUsers", "", &r); err != nil { return err } } *reply = utils.OK return nil }
func (self *ApierV1) ReloadCache(attrs utils.AttrReloadCache, reply *string) error { var dstKeys, rpKeys, rpfKeys, actKeys, aplKeys, shgKeys, lcrKeys, dcsKeys, alsKeys, rlKeys []string if attrs.DestinationIds == nil { dstKeys = nil // Reload all } else if len(*attrs.DestinationIds) > 0 { dstKeys = make([]string, len(*attrs.DestinationIds)) for idx, dId := range *attrs.DestinationIds { dstKeys[idx] = utils.DESTINATION_PREFIX + dId // Cache expects them as redis keys } } if attrs.RatingPlanIds == nil { rpKeys = nil } else if len(*attrs.RatingPlanIds) > 0 { rpKeys = make([]string, len(*attrs.RatingPlanIds)) for idx, rpId := range *attrs.RatingPlanIds { rpKeys[idx] = utils.RATING_PLAN_PREFIX + rpId } } if attrs.RatingProfileIds == nil { rpfKeys = nil } else if len(*attrs.RatingProfileIds) > 0 { rpfKeys = make([]string, len(*attrs.RatingProfileIds)) for idx, rpfId := range *attrs.RatingProfileIds { rpfKeys[idx] = utils.RATING_PROFILE_PREFIX + rpfId } } if attrs.ActionIds == nil { actKeys = nil } else if len(*attrs.ActionIds) > 0 { actKeys = make([]string, len(*attrs.ActionIds)) for idx, actId := range *attrs.ActionIds { actKeys[idx] = utils.ACTION_PREFIX + actId } } if attrs.ActionPlanIds == nil { aplKeys = nil } else if len(*attrs.ActionPlanIds) > 0 { aplKeys = make([]string, len(*attrs.ActionPlanIds)) for idx, aplId := range *attrs.ActionPlanIds { aplKeys[idx] = utils.ACTION_PLAN_PREFIX + aplId } } if attrs.SharedGroupIds == nil { shgKeys = nil } else if len(*attrs.SharedGroupIds) > 0 { shgKeys = make([]string, len(*attrs.SharedGroupIds)) for idx, shgId := range *attrs.SharedGroupIds { shgKeys[idx] = utils.SHARED_GROUP_PREFIX + shgId } } if attrs.LCRIds == nil { lcrKeys = nil } else if len(*attrs.LCRIds) > 0 { lcrKeys = make([]string, len(*attrs.LCRIds)) for idx, lcrId := range *attrs.LCRIds { lcrKeys[idx] = utils.LCR_PREFIX + lcrId } } if attrs.DerivedChargers == nil { dcsKeys = nil } else if len(*attrs.DerivedChargers) > 0 { dcsKeys = make([]string, len(*attrs.DerivedChargers)) for idx, dc := range *attrs.DerivedChargers { dcsKeys[idx] = utils.DERIVEDCHARGERS_PREFIX + dc } } if attrs.Aliases == nil { alsKeys = nil } else if len(*attrs.Aliases) > 0 { alsKeys = make([]string, len(*attrs.Aliases)) for idx, alias := range *attrs.Aliases { alsKeys[idx] = utils.ALIASES_PREFIX + alias } } if attrs.ResourceLimits == nil { rlKeys = nil } else if len(*attrs.ResourceLimits) > 0 { rlKeys = make([]string, len(*attrs.ResourceLimits)) for idx, rlID := range *attrs.ResourceLimits { rlKeys[idx] = utils.ResourceLimitsPrefix + rlID } } // FixMe with CacheS cache.Flush() self.RatingDb.PreloadRatingCache() self.AccountDb.PreloadAccountingCache() *reply = utils.OK return nil }
// Loads complete data in a TP from storDb func (self *ApierV1) LoadTariffPlanFromStorDb(attrs AttrLoadTpFromStorDb, reply *string) error { if len(attrs.TPid) == 0 { return utils.NewErrMandatoryIeMissing("TPid") } dbReader := engine.NewTpReader(self.RatingDb, self.AccountDb, self.StorDb, attrs.TPid, self.Config.DefaultTimezone) if err := dbReader.LoadAll(); err != nil { return utils.NewErrServerError(err) } if attrs.Validate { if !dbReader.IsValid() { *reply = OK return errors.New("invalid data") } } if attrs.DryRun { *reply = OK return nil // Mission complete, no errors } if err := dbReader.WriteToDatabase(attrs.FlushDb, false, false); err != nil { return utils.NewErrServerError(err) } // Make sure the items are in the cache dstIds, _ := dbReader.GetLoadedIds(utils.DESTINATION_PREFIX) dstKeys := make([]string, len(dstIds)) for idx, dId := range dstIds { dstKeys[idx] = utils.DESTINATION_PREFIX + dId // Cache expects them as redis keys } rplIds, _ := dbReader.GetLoadedIds(utils.RATING_PLAN_PREFIX) rpKeys := make([]string, len(rplIds)) for idx, rpId := range rplIds { rpKeys[idx] = utils.RATING_PLAN_PREFIX + rpId } rpfIds, _ := dbReader.GetLoadedIds(utils.RATING_PROFILE_PREFIX) rpfKeys := make([]string, len(rpfIds)) for idx, rpfId := range rpfIds { rpfKeys[idx] = utils.RATING_PROFILE_PREFIX + rpfId } actIds, _ := dbReader.GetLoadedIds(utils.ACTION_PREFIX) actKeys := make([]string, len(actIds)) for idx, actId := range actIds { actKeys[idx] = utils.ACTION_PREFIX + actId } aplIds, _ := dbReader.GetLoadedIds(utils.ACTION_PLAN_PREFIX) aplKeys := make([]string, len(aplIds)) for idx, aplId := range aplIds { aplKeys[idx] = utils.ACTION_PLAN_PREFIX + aplId } shgIds, _ := dbReader.GetLoadedIds(utils.SHARED_GROUP_PREFIX) shgKeys := make([]string, len(shgIds)) for idx, shgId := range shgIds { shgKeys[idx] = utils.SHARED_GROUP_PREFIX + shgId } aliases, _ := dbReader.GetLoadedIds(utils.ALIASES_PREFIX) alsKeys := make([]string, len(aliases)) for idx, alias := range aliases { alsKeys[idx] = utils.ALIASES_PREFIX + alias } lcrIds, _ := dbReader.GetLoadedIds(utils.LCR_PREFIX) lcrKeys := make([]string, len(lcrIds)) for idx, lcrId := range lcrIds { lcrKeys[idx] = utils.LCR_PREFIX + lcrId } dcs, _ := dbReader.GetLoadedIds(utils.DERIVEDCHARGERS_PREFIX) dcsKeys := make([]string, len(dcs)) for idx, dc := range dcs { dcsKeys[idx] = utils.DERIVEDCHARGERS_PREFIX + dc } aps, _ := dbReader.GetLoadedIds(utils.ACTION_PLAN_PREFIX) cstKeys, _ := dbReader.GetLoadedIds(utils.CDR_STATS_PREFIX) userKeys, _ := dbReader.GetLoadedIds(utils.USERS_PREFIX) // relase tp data dbReader.Init() cache.Flush() self.RatingDb.PreloadRatingCache() self.AccountDb.PreloadAccountingCache() if len(aps) != 0 && self.Sched != nil { utils.Logger.Info("ApierV1.LoadTariffPlanFromStorDb, reloading scheduler.") self.Sched.Reload(true) } if len(cstKeys) != 0 && self.CdrStatsSrv != nil { var out int if err := self.CdrStatsSrv.Call("CDRStatsV1.ReloadQueues", cstKeys, &out); err != nil { return err } } if len(userKeys) != 0 && self.Users != nil { var r string if err := self.Users.Call("AliasV1.ReloadUsers", "", &r); err != nil { return err } } *reply = OK return nil }
func testOnStorITFlush(t *testing.T) { if err := onStor.Flush(""); err != nil { t.Error(err) } cache.Flush() }