mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-11 10:06: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
@@ -1671,7 +1671,7 @@ func testApierResetDataAfterLoadFromFolder(t *testing.T) {
|
|||||||
// expStats[utils.CacheActionPlans].Items = 7
|
// expStats[utils.CacheActionPlans].Items = 7
|
||||||
expStats[utils.CacheActions].Items = 5
|
expStats[utils.CacheActions].Items = 5
|
||||||
expStats[utils.CacheDestinations].Items = 3
|
expStats[utils.CacheDestinations].Items = 3
|
||||||
expStats[utils.CacheLoadIDs].Items = 19
|
expStats[utils.CacheLoadIDs].Items = 20
|
||||||
expStats[utils.CacheRPCConnections].Items = 2
|
expStats[utils.CacheRPCConnections].Items = 2
|
||||||
if err := rater.Call(context.Background(), utils.CacheSv1GetCacheStats, new(utils.AttrCacheIDsWithAPIOpts), &rcvStats); err != nil {
|
if err := rater.Call(context.Background(), utils.CacheSv1GetCacheStats, new(utils.AttrCacheIDsWithAPIOpts), &rcvStats); err != nil {
|
||||||
t.Error("Got error on CacheSv1.GetCacheStats: ", err.Error())
|
t.Error("Got error on CacheSv1.GetCacheStats: ", err.Error())
|
||||||
|
|||||||
@@ -133,7 +133,7 @@ func testCacheSAfterLoadFromFolder(t *testing.T) {
|
|||||||
expStats := engine.GetDefaultEmptyCacheStats()
|
expStats := engine.GetDefaultEmptyCacheStats()
|
||||||
expStats[utils.CacheActions].Items = 5
|
expStats[utils.CacheActions].Items = 5
|
||||||
expStats[utils.CacheDestinations].Items = 3
|
expStats[utils.CacheDestinations].Items = 3
|
||||||
expStats[utils.CacheLoadIDs].Items = 19
|
expStats[utils.CacheLoadIDs].Items = 20
|
||||||
expStats[utils.CacheRPCConnections].Items = 2
|
expStats[utils.CacheRPCConnections].Items = 2
|
||||||
if err := chcRPC.Call(context.Background(), utils.CacheSv1GetCacheStats, &utils.AttrCacheIDsWithAPIOpts{}, &rcvStats); err != nil {
|
if err := chcRPC.Call(context.Background(), utils.CacheSv1GetCacheStats, &utils.AttrCacheIDsWithAPIOpts{}, &rcvStats); err != nil {
|
||||||
t.Error("Got error on CacheSv1.GetCacheStats: ", err.Error())
|
t.Error("Got error on CacheSv1.GetCacheStats: ", err.Error())
|
||||||
|
|||||||
@@ -1661,7 +1661,7 @@ func (dm *DataManager) RemoveRankingProfile(tenant, id string) (err error) {
|
|||||||
if dm == nil {
|
if dm == nil {
|
||||||
return utils.ErrNoDatabaseConn
|
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 {
|
if err != nil && err != utils.ErrNotFound {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -1680,7 +1680,7 @@ func (dm *DataManager) RemoveRankingProfile(tenant, id string) (err error) {
|
|||||||
APIOpts: utils.GenerateDBItemOpts(itm.APIKey, itm.RouteID,
|
APIOpts: utils.GenerateDBItemOpts(itm.APIKey, itm.RouteID,
|
||||||
config.CgrConfig().DataDbCfg().RplCache, utils.EmptyString),
|
config.CgrConfig().DataDbCfg().RplCache, utils.EmptyString),
|
||||||
}, itm)
|
}, itm)
|
||||||
return
|
return dm.RemoveRanking(tenant, id)
|
||||||
}
|
}
|
||||||
func (dm *DataManager) GetRanking(tenant, id string, cacheRead, cacheWrite bool, transactionID string) (rn *Ranking, err error) {
|
func (dm *DataManager) GetRanking(tenant, id string, cacheRead, cacheWrite bool, transactionID string) (rn *Ranking, err error) {
|
||||||
tntID := utils.ConcatenatedKey(tenant, id)
|
tntID := utils.ConcatenatedKey(tenant, id)
|
||||||
|
|||||||
@@ -99,6 +99,7 @@ func (tpr *TpReader) Init() {
|
|||||||
tpr.sqProfiles = make(map[utils.TenantID]*utils.TPStatProfile)
|
tpr.sqProfiles = make(map[utils.TenantID]*utils.TPStatProfile)
|
||||||
tpr.rgProfiles = make(map[utils.TenantID]*utils.TPRankingProfile)
|
tpr.rgProfiles = make(map[utils.TenantID]*utils.TPRankingProfile)
|
||||||
tpr.thProfiles = make(map[utils.TenantID]*utils.TPThresholdProfile)
|
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.routeProfiles = make(map[utils.TenantID]*utils.TPRouteProfile)
|
||||||
tpr.attributeProfiles = make(map[utils.TenantID]*utils.TPAttributeProfile)
|
tpr.attributeProfiles = make(map[utils.TenantID]*utils.TPAttributeProfile)
|
||||||
tpr.chargerProfiles = make(map[utils.TenantID]*utils.TPChargerProfile)
|
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())
|
log.Print("\t", tr.TenantID())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if len(tpr.trProfiles) != 0 {
|
||||||
|
loadIDs[utils.CacheTrendProfiles] = loadID
|
||||||
|
}
|
||||||
if verbose {
|
if verbose {
|
||||||
log.Print("RankingProfiles:")
|
log.Print("RankingProfiles:")
|
||||||
}
|
}
|
||||||
@@ -1883,6 +1887,10 @@ func (tpr *TpReader) ShowStatistics() {
|
|||||||
log.Print("Stats: ", len(tpr.sqProfiles))
|
log.Print("Stats: ", len(tpr.sqProfiles))
|
||||||
// thresholds
|
// thresholds
|
||||||
log.Print("Thresholds: ", len(tpr.thProfiles))
|
log.Print("Thresholds: ", len(tpr.thProfiles))
|
||||||
|
// trends
|
||||||
|
log.Print("Trends: ", len(tpr.trProfiles))
|
||||||
|
// rankings
|
||||||
|
log.Print("Rankings: ", len(tpr.rgProfiles))
|
||||||
// filters
|
// filters
|
||||||
log.Print("Filters: ", len(tpr.filters))
|
log.Print("Filters: ", len(tpr.filters))
|
||||||
// Route profiles
|
// Route profiles
|
||||||
@@ -2012,6 +2020,14 @@ func (tpr *TpReader) GetLoadedIds(categ string) ([]string, error) {
|
|||||||
i++
|
i++
|
||||||
}
|
}
|
||||||
return keys, nil
|
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:
|
case utils.ThresholdProfilePrefix:
|
||||||
keys := make([]string, len(tpr.thProfiles))
|
keys := make([]string, len(tpr.thProfiles))
|
||||||
i := 0
|
i := 0
|
||||||
@@ -2206,6 +2222,17 @@ func (tpr *TpReader) RemoveFromDatabase(verbose, disableReverse bool) (err error
|
|||||||
log.Print("\t", utils.ConcatenatedKey(tpSgs.Tenant, tpSgs.ID))
|
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 {
|
if verbose {
|
||||||
log.Print("ThresholdProfiles:")
|
log.Print("ThresholdProfiles:")
|
||||||
}
|
}
|
||||||
@@ -2361,6 +2388,9 @@ func (tpr *TpReader) RemoveFromDatabase(verbose, disableReverse bool) (err error
|
|||||||
if len(tpr.rgProfiles) != 0 {
|
if len(tpr.rgProfiles) != 0 {
|
||||||
loadIDs[utils.CacheRankingProfiles] = loadID
|
loadIDs[utils.CacheRankingProfiles] = loadID
|
||||||
}
|
}
|
||||||
|
if len(tpr.trProfiles) != 0 {
|
||||||
|
loadIDs[utils.CacheTrendProfiles] = loadID
|
||||||
|
}
|
||||||
if len(tpr.thProfiles) != 0 {
|
if len(tpr.thProfiles) != 0 {
|
||||||
loadIDs[utils.CacheThresholdProfiles] = loadID
|
loadIDs[utils.CacheThresholdProfiles] = loadID
|
||||||
loadIDs[utils.CacheThresholds] = 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)
|
aatIDs, _ := tpr.GetLoadedIds(utils.ActionTriggerPrefix)
|
||||||
stqpIDs, _ := tpr.GetLoadedIds(utils.StatQueueProfilePrefix)
|
stqpIDs, _ := tpr.GetLoadedIds(utils.StatQueueProfilePrefix)
|
||||||
sgIDS, _ := tpr.GetLoadedIds(utils.RankingsProfilePrefix)
|
sgIDS, _ := tpr.GetLoadedIds(utils.RankingsProfilePrefix)
|
||||||
|
trIDS, _ := tpr.GetLoadedIds(utils.TrendsProfilePrefix)
|
||||||
trspfIDs, _ := tpr.GetLoadedIds(utils.ThresholdProfilePrefix)
|
trspfIDs, _ := tpr.GetLoadedIds(utils.ThresholdProfilePrefix)
|
||||||
flrIDs, _ := tpr.GetLoadedIds(utils.FilterPrefix)
|
flrIDs, _ := tpr.GetLoadedIds(utils.FilterPrefix)
|
||||||
routeIDs, _ := tpr.GetLoadedIds(utils.RouteProfilePrefix)
|
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.CacheStatQueues: stqpIDs,
|
||||||
utils.CacheStatQueueProfiles: stqpIDs,
|
utils.CacheStatQueueProfiles: stqpIDs,
|
||||||
utils.CacheRankingProfiles: sgIDS,
|
utils.CacheRankingProfiles: sgIDS,
|
||||||
|
utils.CacheTrendProfiles: trIDS,
|
||||||
utils.CacheThresholds: trspfIDs,
|
utils.CacheThresholds: trspfIDs,
|
||||||
utils.CacheThresholdProfiles: trspfIDs,
|
utils.CacheThresholdProfiles: trspfIDs,
|
||||||
utils.CacheFilters: flrIDs,
|
utils.CacheFilters: flrIDs,
|
||||||
|
|||||||
@@ -940,6 +940,7 @@ func TestTPReaderReloadCache(t *testing.T) {
|
|||||||
IPProfileIDs: []string{"cgrates.org:ipProfilesID"},
|
IPProfileIDs: []string{"cgrates.org:ipProfilesID"},
|
||||||
StatsQueueProfileIDs: []string{"cgrates.org:statProfilesID"},
|
StatsQueueProfileIDs: []string{"cgrates.org:statProfilesID"},
|
||||||
ThresholdProfileIDs: []string{"cgrates.org:thresholdProfilesID"},
|
ThresholdProfileIDs: []string{"cgrates.org:thresholdProfilesID"},
|
||||||
|
TrendProfileIDs: []string{"cgrates.org:trendProfilesID"},
|
||||||
FilterIDs: []string{"cgrates.org:filtersID"},
|
FilterIDs: []string{"cgrates.org:filtersID"},
|
||||||
RouteProfileIDs: []string{"cgrates.org:routeProfilesID"},
|
RouteProfileIDs: []string{"cgrates.org:routeProfilesID"},
|
||||||
AttributeProfileIDs: []string{"cgrates.org:attributeProfilesID"},
|
AttributeProfileIDs: []string{"cgrates.org:attributeProfilesID"},
|
||||||
@@ -1014,6 +1015,9 @@ func TestTPReaderReloadCache(t *testing.T) {
|
|||||||
thProfiles: map[utils.TenantID]*utils.TPThresholdProfile{
|
thProfiles: map[utils.TenantID]*utils.TPThresholdProfile{
|
||||||
{Tenant: "cgrates.org", ID: "thresholdProfilesID"}: {},
|
{Tenant: "cgrates.org", ID: "thresholdProfilesID"}: {},
|
||||||
},
|
},
|
||||||
|
trProfiles: map[utils.TenantID]*utils.TPTrendsProfile{
|
||||||
|
{Tenant: "cgrates.org", ID: "trendProfilesID"}: {},
|
||||||
|
},
|
||||||
filters: map[utils.TenantID]*utils.TPFilterProfile{
|
filters: map[utils.TenantID]*utils.TPFilterProfile{
|
||||||
{Tenant: "cgrates.org", ID: "filtersID"}: {},
|
{Tenant: "cgrates.org", ID: "filtersID"}: {},
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user