mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-11 18:16:24 +05:00
updated tpreader to remove trend and ranking profiles with -remove flag
This commit is contained in:
committed by
Dan Christian Bogos
parent
9d1e2f9050
commit
799b85ca70
@@ -1661,7 +1661,7 @@ func (dm *DataManager) RemoveRankingProfile(tenant, id string) (err error) {
|
||||
if dm == nil {
|
||||
return utils.ErrNoDatabaseConn
|
||||
}
|
||||
oldSgs, err := dm.GetRankingProfile(tenant, id, true, false, utils.NonTransactional)
|
||||
oldSgs, err := dm.GetRankingProfile(tenant, id, false, false, utils.NonTransactional)
|
||||
if err != nil && err != utils.ErrNotFound {
|
||||
return err
|
||||
}
|
||||
@@ -1680,7 +1680,7 @@ func (dm *DataManager) RemoveRankingProfile(tenant, id string) (err error) {
|
||||
APIOpts: utils.GenerateDBItemOpts(itm.APIKey, itm.RouteID,
|
||||
config.CgrConfig().DataDbCfg().RplCache, utils.EmptyString),
|
||||
}, itm)
|
||||
return
|
||||
return dm.RemoveRanking(tenant, id)
|
||||
}
|
||||
func (dm *DataManager) GetRanking(tenant, id string, cacheRead, cacheWrite bool, transactionID string) (rn *Ranking, err error) {
|
||||
tntID := utils.ConcatenatedKey(tenant, id)
|
||||
|
||||
@@ -99,6 +99,7 @@ func (tpr *TpReader) Init() {
|
||||
tpr.sqProfiles = make(map[utils.TenantID]*utils.TPStatProfile)
|
||||
tpr.rgProfiles = make(map[utils.TenantID]*utils.TPRankingProfile)
|
||||
tpr.thProfiles = make(map[utils.TenantID]*utils.TPThresholdProfile)
|
||||
tpr.trProfiles = make(map[utils.TenantID]*utils.TPTrendsProfile)
|
||||
tpr.routeProfiles = make(map[utils.TenantID]*utils.TPRouteProfile)
|
||||
tpr.attributeProfiles = make(map[utils.TenantID]*utils.TPAttributeProfile)
|
||||
tpr.chargerProfiles = make(map[utils.TenantID]*utils.TPChargerProfile)
|
||||
@@ -1672,6 +1673,9 @@ func (tpr *TpReader) WriteToDatabase(verbose, disableReverse bool) (err error) {
|
||||
log.Print("\t", tr.TenantID())
|
||||
}
|
||||
}
|
||||
if len(tpr.trProfiles) != 0 {
|
||||
loadIDs[utils.CacheTrendProfiles] = loadID
|
||||
}
|
||||
if verbose {
|
||||
log.Print("RankingProfiles:")
|
||||
}
|
||||
@@ -1883,6 +1887,10 @@ func (tpr *TpReader) ShowStatistics() {
|
||||
log.Print("Stats: ", len(tpr.sqProfiles))
|
||||
// thresholds
|
||||
log.Print("Thresholds: ", len(tpr.thProfiles))
|
||||
// trends
|
||||
log.Print("Trends: ", len(tpr.trProfiles))
|
||||
// rankings
|
||||
log.Print("Rankings: ", len(tpr.rgProfiles))
|
||||
// filters
|
||||
log.Print("Filters: ", len(tpr.filters))
|
||||
// Route profiles
|
||||
@@ -2012,6 +2020,14 @@ func (tpr *TpReader) GetLoadedIds(categ string) ([]string, error) {
|
||||
i++
|
||||
}
|
||||
return keys, nil
|
||||
case utils.TrendsProfilePrefix:
|
||||
keys := make([]string, len(tpr.trProfiles))
|
||||
i := 0
|
||||
for k := range tpr.trProfiles {
|
||||
keys[i] = k.TenantID()
|
||||
i++
|
||||
}
|
||||
return keys, nil
|
||||
case utils.ThresholdProfilePrefix:
|
||||
keys := make([]string, len(tpr.thProfiles))
|
||||
i := 0
|
||||
@@ -2206,6 +2222,17 @@ func (tpr *TpReader) RemoveFromDatabase(verbose, disableReverse bool) (err error
|
||||
log.Print("\t", utils.ConcatenatedKey(tpSgs.Tenant, tpSgs.ID))
|
||||
}
|
||||
}
|
||||
if verbose {
|
||||
log.Print("TrendProfiles:")
|
||||
}
|
||||
for _, tpTR := range tpr.trProfiles {
|
||||
if err = tpr.dm.RemoveTrendProfile(tpTR.Tenant, tpTR.ID); err != nil {
|
||||
return
|
||||
}
|
||||
if verbose {
|
||||
log.Print("\t", utils.ConcatenatedKey(tpTR.Tenant, tpTR.ID))
|
||||
}
|
||||
}
|
||||
if verbose {
|
||||
log.Print("ThresholdProfiles:")
|
||||
}
|
||||
@@ -2361,6 +2388,9 @@ func (tpr *TpReader) RemoveFromDatabase(verbose, disableReverse bool) (err error
|
||||
if len(tpr.rgProfiles) != 0 {
|
||||
loadIDs[utils.CacheRankingProfiles] = loadID
|
||||
}
|
||||
if len(tpr.trProfiles) != 0 {
|
||||
loadIDs[utils.CacheTrendProfiles] = loadID
|
||||
}
|
||||
if len(tpr.thProfiles) != 0 {
|
||||
loadIDs[utils.CacheThresholdProfiles] = loadID
|
||||
loadIDs[utils.CacheThresholds] = loadID
|
||||
@@ -2405,6 +2435,7 @@ func (tpr *TpReader) ReloadCache(caching string, verbose bool, opts map[string]a
|
||||
aatIDs, _ := tpr.GetLoadedIds(utils.ActionTriggerPrefix)
|
||||
stqpIDs, _ := tpr.GetLoadedIds(utils.StatQueueProfilePrefix)
|
||||
sgIDS, _ := tpr.GetLoadedIds(utils.RankingsProfilePrefix)
|
||||
trIDS, _ := tpr.GetLoadedIds(utils.TrendsProfilePrefix)
|
||||
trspfIDs, _ := tpr.GetLoadedIds(utils.ThresholdProfilePrefix)
|
||||
flrIDs, _ := tpr.GetLoadedIds(utils.FilterPrefix)
|
||||
routeIDs, _ := tpr.GetLoadedIds(utils.RouteProfilePrefix)
|
||||
@@ -2433,6 +2464,7 @@ func (tpr *TpReader) ReloadCache(caching string, verbose bool, opts map[string]a
|
||||
utils.CacheStatQueues: stqpIDs,
|
||||
utils.CacheStatQueueProfiles: stqpIDs,
|
||||
utils.CacheRankingProfiles: sgIDS,
|
||||
utils.CacheTrendProfiles: trIDS,
|
||||
utils.CacheThresholds: trspfIDs,
|
||||
utils.CacheThresholdProfiles: trspfIDs,
|
||||
utils.CacheFilters: flrIDs,
|
||||
|
||||
@@ -940,6 +940,7 @@ func TestTPReaderReloadCache(t *testing.T) {
|
||||
IPProfileIDs: []string{"cgrates.org:ipProfilesID"},
|
||||
StatsQueueProfileIDs: []string{"cgrates.org:statProfilesID"},
|
||||
ThresholdProfileIDs: []string{"cgrates.org:thresholdProfilesID"},
|
||||
TrendProfileIDs: []string{"cgrates.org:trendProfilesID"},
|
||||
FilterIDs: []string{"cgrates.org:filtersID"},
|
||||
RouteProfileIDs: []string{"cgrates.org:routeProfilesID"},
|
||||
AttributeProfileIDs: []string{"cgrates.org:attributeProfilesID"},
|
||||
@@ -1014,6 +1015,9 @@ func TestTPReaderReloadCache(t *testing.T) {
|
||||
thProfiles: map[utils.TenantID]*utils.TPThresholdProfile{
|
||||
{Tenant: "cgrates.org", ID: "thresholdProfilesID"}: {},
|
||||
},
|
||||
trProfiles: map[utils.TenantID]*utils.TPTrendsProfile{
|
||||
{Tenant: "cgrates.org", ID: "trendProfilesID"}: {},
|
||||
},
|
||||
filters: map[utils.TenantID]*utils.TPFilterProfile{
|
||||
{Tenant: "cgrates.org", ID: "filtersID"}: {},
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user