mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-11 18:16:24 +05:00
Allow Get items from cache before verification DataManager for nil fixes #2075
This commit is contained in:
committed by
Dan Christian Bogos
parent
4d5c202aea
commit
30f339247b
@@ -214,6 +214,10 @@ func testPrecacheGetCacheStatsAfterRestart(t *testing.T) {
|
||||
Items: 5,
|
||||
Groups: 0,
|
||||
},
|
||||
utils.CacheDispatchers: {
|
||||
Items: 5,
|
||||
Groups: 0,
|
||||
},
|
||||
utils.CacheEventResources: {
|
||||
Items: 0,
|
||||
Groups: 0,
|
||||
|
||||
@@ -542,10 +542,6 @@ func (dm *DataManager) RemoveAccount(id string) (err error) {
|
||||
// handles caching and deserialization of metrics
|
||||
func (dm *DataManager) GetStatQueue(tenant, id string,
|
||||
cacheRead, cacheWrite bool, transactionID string) (sq *StatQueue, err error) {
|
||||
if dm == nil {
|
||||
err = utils.ErrNoDatabaseConn
|
||||
return
|
||||
}
|
||||
tntID := utils.ConcatenatedKey(tenant, id)
|
||||
if cacheRead {
|
||||
if x, ok := Cache.Get(utils.CacheStatQueues, tntID); ok {
|
||||
@@ -555,6 +551,10 @@ func (dm *DataManager) GetStatQueue(tenant, id string,
|
||||
return x.(*StatQueue), nil
|
||||
}
|
||||
}
|
||||
if dm == nil {
|
||||
err = utils.ErrNoDatabaseConn
|
||||
return
|
||||
}
|
||||
sq, err = dm.dataDB.GetStatQueueDrv(tenant, id)
|
||||
if err != nil {
|
||||
if itm := config.CgrConfig().DataDbCfg().Items[utils.MetaStatQueues]; err == utils.ErrNotFound && itm.Remote {
|
||||
@@ -747,10 +747,6 @@ func (dm *DataManager) RemoveFilter(tenant, id, transactionID string) (err error
|
||||
|
||||
func (dm *DataManager) GetThreshold(tenant, id string,
|
||||
cacheRead, cacheWrite bool, transactionID string) (th *Threshold, err error) {
|
||||
if dm == nil {
|
||||
err = utils.ErrNoDatabaseConn
|
||||
return
|
||||
}
|
||||
tntID := utils.ConcatenatedKey(tenant, id)
|
||||
if cacheRead {
|
||||
if x, ok := Cache.Get(utils.CacheThresholds, tntID); ok {
|
||||
@@ -760,6 +756,10 @@ func (dm *DataManager) GetThreshold(tenant, id string,
|
||||
return x.(*Threshold), nil
|
||||
}
|
||||
}
|
||||
if dm == nil {
|
||||
err = utils.ErrNoDatabaseConn
|
||||
return
|
||||
}
|
||||
th, err = dm.dataDB.GetThresholdDrv(tenant, id)
|
||||
if err != nil {
|
||||
if itm := config.CgrConfig().DataDbCfg().Items[utils.MetaThresholds]; err == utils.ErrNotFound && itm.Remote {
|
||||
@@ -837,10 +837,6 @@ func (dm *DataManager) RemoveThreshold(tenant, id, transactionID string) (err er
|
||||
|
||||
func (dm *DataManager) GetThresholdProfile(tenant, id string, cacheRead, cacheWrite bool,
|
||||
transactionID string) (th *ThresholdProfile, err error) {
|
||||
if dm == nil {
|
||||
err = utils.ErrNoDatabaseConn
|
||||
return
|
||||
}
|
||||
tntID := utils.ConcatenatedKey(tenant, id)
|
||||
if cacheRead {
|
||||
if x, ok := Cache.Get(utils.CacheThresholdProfiles, tntID); ok {
|
||||
@@ -850,6 +846,10 @@ func (dm *DataManager) GetThresholdProfile(tenant, id string, cacheRead, cacheWr
|
||||
return x.(*ThresholdProfile), nil
|
||||
}
|
||||
}
|
||||
if dm == nil {
|
||||
err = utils.ErrNoDatabaseConn
|
||||
return
|
||||
}
|
||||
th, err = dm.dataDB.GetThresholdProfileDrv(tenant, id)
|
||||
if err != nil {
|
||||
if itm := config.CgrConfig().DataDbCfg().Items[utils.MetaThresholdProfiles]; err == utils.ErrNotFound && itm.Remote {
|
||||
@@ -967,10 +967,6 @@ func (dm *DataManager) RemoveThresholdProfile(tenant, id,
|
||||
|
||||
func (dm *DataManager) GetStatQueueProfile(tenant, id string, cacheRead, cacheWrite bool,
|
||||
transactionID string) (sqp *StatQueueProfile, err error) {
|
||||
if dm == nil {
|
||||
err = utils.ErrNoDatabaseConn
|
||||
return
|
||||
}
|
||||
tntID := utils.ConcatenatedKey(tenant, id)
|
||||
if cacheRead {
|
||||
if x, ok := Cache.Get(utils.CacheStatQueueProfiles, tntID); ok {
|
||||
@@ -980,6 +976,10 @@ func (dm *DataManager) GetStatQueueProfile(tenant, id string, cacheRead, cacheWr
|
||||
return x.(*StatQueueProfile), nil
|
||||
}
|
||||
}
|
||||
if dm == nil {
|
||||
err = utils.ErrNoDatabaseConn
|
||||
return
|
||||
}
|
||||
sqp, err = dm.dataDB.GetStatQueueProfileDrv(tenant, id)
|
||||
if err != nil {
|
||||
if itm := config.CgrConfig().DataDbCfg().Items[utils.MetaStatQueueProfiles]; err == utils.ErrNotFound && itm.Remote {
|
||||
@@ -1097,10 +1097,6 @@ func (dm *DataManager) RemoveStatQueueProfile(tenant, id,
|
||||
|
||||
func (dm *DataManager) GetTiming(id string, skipCache bool,
|
||||
transactionID string) (t *utils.TPTiming, err error) {
|
||||
if dm == nil {
|
||||
err = utils.ErrNoDatabaseConn
|
||||
return
|
||||
}
|
||||
if !skipCache {
|
||||
if x, ok := Cache.Get(utils.CacheTimings, id); ok {
|
||||
if x == nil {
|
||||
@@ -1109,6 +1105,10 @@ func (dm *DataManager) GetTiming(id string, skipCache bool,
|
||||
return x.(*utils.TPTiming), nil
|
||||
}
|
||||
}
|
||||
if dm == nil {
|
||||
err = utils.ErrNoDatabaseConn
|
||||
return
|
||||
}
|
||||
t, err = dm.dataDB.GetTimingDrv(id)
|
||||
if err != nil {
|
||||
if itm := config.CgrConfig().DataDbCfg().Items[utils.MetaTimings]; err == utils.ErrNotFound && itm.Remote {
|
||||
@@ -1187,10 +1187,6 @@ func (dm *DataManager) RemoveTiming(id, transactionID string) (err error) {
|
||||
|
||||
func (dm *DataManager) GetResource(tenant, id string, cacheRead, cacheWrite bool,
|
||||
transactionID string) (rs *Resource, err error) {
|
||||
if dm == nil {
|
||||
err = utils.ErrNoDatabaseConn
|
||||
return
|
||||
}
|
||||
tntID := utils.ConcatenatedKey(tenant, id)
|
||||
if cacheRead {
|
||||
if x, ok := Cache.Get(utils.CacheResources, tntID); ok {
|
||||
@@ -1200,6 +1196,10 @@ func (dm *DataManager) GetResource(tenant, id string, cacheRead, cacheWrite bool
|
||||
return x.(*Resource), nil
|
||||
}
|
||||
}
|
||||
if dm == nil {
|
||||
err = utils.ErrNoDatabaseConn
|
||||
return
|
||||
}
|
||||
rs, err = dm.dataDB.GetResourceDrv(tenant, id)
|
||||
if err != nil {
|
||||
if itm := config.CgrConfig().DataDbCfg().Items[utils.MetaResources]; err == utils.ErrNotFound && itm.Remote {
|
||||
@@ -1280,10 +1280,6 @@ func (dm *DataManager) RemoveResource(tenant, id, transactionID string) (err err
|
||||
|
||||
func (dm *DataManager) GetResourceProfile(tenant, id string, cacheRead, cacheWrite bool,
|
||||
transactionID string) (rp *ResourceProfile, err error) {
|
||||
if dm == nil {
|
||||
err = utils.ErrNoDatabaseConn
|
||||
return
|
||||
}
|
||||
tntID := utils.ConcatenatedKey(tenant, id)
|
||||
if cacheRead {
|
||||
if x, ok := Cache.Get(utils.CacheResourceProfiles, tntID); ok {
|
||||
@@ -1293,6 +1289,10 @@ func (dm *DataManager) GetResourceProfile(tenant, id string, cacheRead, cacheWri
|
||||
return x.(*ResourceProfile), nil
|
||||
}
|
||||
}
|
||||
if dm == nil {
|
||||
err = utils.ErrNoDatabaseConn
|
||||
return
|
||||
}
|
||||
rp, err = dm.dataDB.GetResourceProfileDrv(tenant, id)
|
||||
if err != nil {
|
||||
if itm := config.CgrConfig().DataDbCfg().Items[utils.MetaResourceProfile]; err == utils.ErrNotFound && itm.Remote {
|
||||
@@ -1408,10 +1408,6 @@ func (dm *DataManager) RemoveResourceProfile(tenant, id, transactionID string, w
|
||||
|
||||
func (dm *DataManager) GetActionTriggers(id string, skipCache bool,
|
||||
transactionID string) (attrs ActionTriggers, err error) {
|
||||
if dm == nil {
|
||||
err = utils.ErrNoDatabaseConn
|
||||
return
|
||||
}
|
||||
if !skipCache {
|
||||
if x, ok := Cache.Get(utils.CacheActionTriggers, id); ok {
|
||||
if x == nil {
|
||||
@@ -1420,6 +1416,10 @@ func (dm *DataManager) GetActionTriggers(id string, skipCache bool,
|
||||
return x.(ActionTriggers), nil
|
||||
}
|
||||
}
|
||||
if dm == nil {
|
||||
err = utils.ErrNoDatabaseConn
|
||||
return
|
||||
}
|
||||
attrs, err = dm.dataDB.GetActionTriggersDrv(id)
|
||||
if err != nil {
|
||||
if itm := config.CgrConfig().DataDbCfg().Items[utils.MetaActionTriggers]; err == utils.ErrNotFound && itm.Remote {
|
||||
@@ -1513,10 +1513,6 @@ func (dm *DataManager) SetActionTriggers(key string, attr ActionTriggers,
|
||||
|
||||
func (dm *DataManager) GetSharedGroup(key string, skipCache bool,
|
||||
transactionID string) (sg *SharedGroup, err error) {
|
||||
if dm == nil {
|
||||
err = utils.ErrNoDatabaseConn
|
||||
return
|
||||
}
|
||||
if !skipCache {
|
||||
if x, ok := Cache.Get(utils.CacheSharedGroups, key); ok {
|
||||
if x != nil {
|
||||
@@ -1525,6 +1521,10 @@ func (dm *DataManager) GetSharedGroup(key string, skipCache bool,
|
||||
return nil, utils.ErrNotFound
|
||||
}
|
||||
}
|
||||
if dm == nil {
|
||||
err = utils.ErrNoDatabaseConn
|
||||
return
|
||||
}
|
||||
sg, err = dm.DataDB().GetSharedGroupDrv(key)
|
||||
if err != nil {
|
||||
if itm := config.CgrConfig().DataDbCfg().Items[utils.MetaSharedGroups]; err == utils.ErrNotFound && itm.Remote {
|
||||
@@ -1611,10 +1611,6 @@ func (dm *DataManager) RemoveSharedGroup(id, transactionID string) (err error) {
|
||||
}
|
||||
|
||||
func (dm *DataManager) GetActions(key string, skipCache bool, transactionID string) (as Actions, err error) {
|
||||
if dm == nil {
|
||||
err = utils.ErrNoDatabaseConn
|
||||
return
|
||||
}
|
||||
if !skipCache {
|
||||
if x, err := Cache.GetCloned(utils.CacheActions, key); err != nil {
|
||||
if err != ltcache.ErrNotFound {
|
||||
@@ -1626,6 +1622,10 @@ func (dm *DataManager) GetActions(key string, skipCache bool, transactionID stri
|
||||
return x.(Actions), nil
|
||||
}
|
||||
}
|
||||
if dm == nil {
|
||||
err = utils.ErrNoDatabaseConn
|
||||
return
|
||||
}
|
||||
as, err = dm.DataDB().GetActionsDrv(key)
|
||||
if err != nil {
|
||||
if itm := config.CgrConfig().DataDbCfg().Items[utils.MetaActions]; err == utils.ErrNotFound && itm.Remote {
|
||||
@@ -1919,6 +1919,7 @@ func (dm *DataManager) RemAccountActionPlans(acntID string, apIDs []string) (err
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (dm *DataManager) GetRatingPlan(key string, skipCache bool,
|
||||
transactionID string) (rp *RatingPlan, err error) {
|
||||
if !skipCache {
|
||||
@@ -1929,6 +1930,10 @@ func (dm *DataManager) GetRatingPlan(key string, skipCache bool,
|
||||
return nil, utils.ErrNotFound
|
||||
}
|
||||
}
|
||||
if dm == nil {
|
||||
err = utils.ErrNoDatabaseConn
|
||||
return
|
||||
}
|
||||
rp, err = dm.DataDB().GetRatingPlanDrv(key)
|
||||
if err != nil {
|
||||
if itm := config.CgrConfig().DataDbCfg().Items[utils.MetaRatingPlans]; err == utils.ErrNotFound && itm.Remote {
|
||||
@@ -2016,10 +2021,6 @@ func (dm *DataManager) RemoveRatingPlan(key string, transactionID string) (err e
|
||||
// GetRatingProfile returns the RatingProfile for the key
|
||||
func (dm *DataManager) GetRatingProfile(key string, skipCache bool,
|
||||
transactionID string) (rpf *RatingProfile, err error) {
|
||||
if dm == nil {
|
||||
err = utils.ErrNoDatabaseConn
|
||||
return
|
||||
}
|
||||
if !skipCache {
|
||||
for _, cacheRP := range []string{utils.CacheRatingProfilesTmp, utils.CacheRatingProfiles} {
|
||||
if x, ok := Cache.Get(cacheRP, key); ok {
|
||||
@@ -2030,6 +2031,10 @@ func (dm *DataManager) GetRatingProfile(key string, skipCache bool,
|
||||
}
|
||||
}
|
||||
}
|
||||
if dm == nil {
|
||||
err = utils.ErrNoDatabaseConn
|
||||
return
|
||||
}
|
||||
rpf, err = dm.DataDB().GetRatingProfileDrv(key)
|
||||
if err != nil {
|
||||
if itm := config.CgrConfig().DataDbCfg().Items[utils.MetaRatingProfiles]; err == utils.ErrNotFound && itm.Remote {
|
||||
@@ -2266,10 +2271,6 @@ func (dm *DataManager) MatchFilterIndex(cacheID, itemIDPrefix,
|
||||
|
||||
func (dm *DataManager) GetSupplierProfile(tenant, id string, cacheRead, cacheWrite bool,
|
||||
transactionID string) (supp *SupplierProfile, err error) {
|
||||
if dm == nil {
|
||||
err = utils.ErrNoDatabaseConn
|
||||
return
|
||||
}
|
||||
tntID := utils.ConcatenatedKey(tenant, id)
|
||||
if cacheRead {
|
||||
if x, ok := Cache.Get(utils.CacheSupplierProfiles, tntID); ok {
|
||||
@@ -2279,6 +2280,10 @@ func (dm *DataManager) GetSupplierProfile(tenant, id string, cacheRead, cacheWri
|
||||
return x.(*SupplierProfile), nil
|
||||
}
|
||||
}
|
||||
if dm == nil {
|
||||
err = utils.ErrNoDatabaseConn
|
||||
return
|
||||
}
|
||||
supp, err = dm.dataDB.GetSupplierProfileDrv(tenant, id)
|
||||
if err != nil {
|
||||
if itm := config.CgrConfig().DataDbCfg().Items[utils.MetaSupplierProfiles]; err == utils.ErrNotFound && itm.Remote {
|
||||
@@ -2400,10 +2405,6 @@ func (dm *DataManager) RemoveSupplierProfile(tenant, id, transactionID string, w
|
||||
// GetAttributeProfile returns the AttributeProfile with the given id
|
||||
func (dm *DataManager) GetAttributeProfile(tenant, id string, cacheRead, cacheWrite bool,
|
||||
transactionID string) (attrPrfl *AttributeProfile, err error) {
|
||||
if dm == nil {
|
||||
err = utils.ErrNoDatabaseConn
|
||||
return
|
||||
}
|
||||
tntID := utils.ConcatenatedKey(tenant, id)
|
||||
if cacheRead {
|
||||
if x, ok := Cache.Get(utils.CacheAttributeProfiles, tntID); ok {
|
||||
@@ -2557,10 +2558,6 @@ func (dm *DataManager) RemoveAttributeProfile(tenant, id string, transactionID s
|
||||
|
||||
func (dm *DataManager) GetChargerProfile(tenant, id string, cacheRead, cacheWrite bool,
|
||||
transactionID string) (cpp *ChargerProfile, err error) {
|
||||
if dm == nil {
|
||||
err = utils.ErrNoDatabaseConn
|
||||
return
|
||||
}
|
||||
tntID := utils.ConcatenatedKey(tenant, id)
|
||||
if cacheRead {
|
||||
if x, ok := Cache.Get(utils.CacheChargerProfiles, tntID); ok {
|
||||
@@ -2570,6 +2567,10 @@ func (dm *DataManager) GetChargerProfile(tenant, id string, cacheRead, cacheWrit
|
||||
return x.(*ChargerProfile), nil
|
||||
}
|
||||
}
|
||||
if dm == nil {
|
||||
err = utils.ErrNoDatabaseConn
|
||||
return
|
||||
}
|
||||
cpp, err = dm.dataDB.GetChargerProfileDrv(tenant, id)
|
||||
if err != nil {
|
||||
if itm := config.CgrConfig().DataDbCfg().Items[utils.MetaChargerProfiles]; err == utils.ErrNotFound && itm.Remote {
|
||||
@@ -2688,10 +2689,6 @@ func (dm *DataManager) RemoveChargerProfile(tenant, id string,
|
||||
|
||||
func (dm *DataManager) GetDispatcherProfile(tenant, id string, cacheRead, cacheWrite bool,
|
||||
transactionID string) (dpp *DispatcherProfile, err error) {
|
||||
if dm == nil {
|
||||
err = utils.ErrNoDatabaseConn
|
||||
return
|
||||
}
|
||||
tntID := utils.ConcatenatedKey(tenant, id)
|
||||
if cacheRead {
|
||||
if x, ok := Cache.Get(utils.CacheDispatcherProfiles, tntID); ok {
|
||||
@@ -2701,6 +2698,10 @@ func (dm *DataManager) GetDispatcherProfile(tenant, id string, cacheRead, cacheW
|
||||
return x.(*DispatcherProfile), nil
|
||||
}
|
||||
}
|
||||
if dm == nil {
|
||||
err = utils.ErrNoDatabaseConn
|
||||
return
|
||||
}
|
||||
dpp, err = dm.dataDB.GetDispatcherProfileDrv(tenant, id)
|
||||
if err != nil {
|
||||
if itm := config.CgrConfig().DataDbCfg().Items[utils.MetaDispatcherProfiles]; err == utils.ErrNotFound && itm.Remote {
|
||||
@@ -2828,10 +2829,6 @@ func (dm *DataManager) RemoveDispatcherProfile(tenant, id string,
|
||||
|
||||
func (dm *DataManager) GetDispatcherHost(tenant, id string, cacheRead, cacheWrite bool,
|
||||
transactionID string) (dH *DispatcherHost, err error) {
|
||||
if dm == nil {
|
||||
err = utils.ErrNoDatabaseConn
|
||||
return
|
||||
}
|
||||
tntID := utils.ConcatenatedKey(tenant, id)
|
||||
if cacheRead {
|
||||
if x, ok := Cache.Get(utils.CacheDispatcherHosts, tntID); ok {
|
||||
@@ -2841,6 +2838,10 @@ func (dm *DataManager) GetDispatcherHost(tenant, id string, cacheRead, cacheWrit
|
||||
return x.(*DispatcherHost), nil
|
||||
}
|
||||
}
|
||||
if dm == nil {
|
||||
err = utils.ErrNoDatabaseConn
|
||||
return
|
||||
}
|
||||
dH, err = dm.dataDB.GetDispatcherHostDrv(tenant, id)
|
||||
if err != nil {
|
||||
if itm := config.CgrConfig().DataDbCfg().Items[utils.MetaDispatcherHosts]; err == utils.ErrNotFound && itm.Remote {
|
||||
|
||||
@@ -1676,7 +1676,7 @@ func testOnStorITFilter(t *testing.T) {
|
||||
ExpiryTime: time.Date(2014, 7, 14, 14, 25, 0, 0, time.UTC),
|
||||
},
|
||||
}
|
||||
if _, rcvErr := GetFilter(onStor, "cgrates.org", "Filter1",
|
||||
if _, rcvErr := onStor.GetFilter("cgrates.org", "Filter1",
|
||||
true, false, utils.NonTransactional); rcvErr != nil && rcvErr != utils.ErrNotFound {
|
||||
t.Error(rcvErr)
|
||||
}
|
||||
@@ -1684,14 +1684,14 @@ func testOnStorITFilter(t *testing.T) {
|
||||
t.Error(err)
|
||||
}
|
||||
//get from cache
|
||||
if rcv, err := GetFilter(onStor, "cgrates.org", "Filter1",
|
||||
if rcv, err := onStor.GetFilter("cgrates.org", "Filter1",
|
||||
true, false, utils.NonTransactional); err != nil {
|
||||
t.Error(err)
|
||||
} else if !(reflect.DeepEqual(fp, rcv)) {
|
||||
t.Errorf("Expecting: %v, received: %v", fp, rcv)
|
||||
}
|
||||
//get from database
|
||||
if rcv, err := GetFilter(onStor, "cgrates.org", "Filter1",
|
||||
if rcv, err := onStor.GetFilter("cgrates.org", "Filter1",
|
||||
false, false, utils.NonTransactional); err != nil {
|
||||
t.Error(err)
|
||||
} else if !(reflect.DeepEqual(fp, rcv)) {
|
||||
@@ -1721,14 +1721,14 @@ func testOnStorITFilter(t *testing.T) {
|
||||
}
|
||||
time.Sleep(sleepDelay)
|
||||
//get from cache
|
||||
if rcv, err := GetFilter(onStor, "cgrates.org", "Filter1",
|
||||
if rcv, err := onStor.GetFilter("cgrates.org", "Filter1",
|
||||
true, false, utils.NonTransactional); err != nil {
|
||||
t.Error(err)
|
||||
} else if !(reflect.DeepEqual(fp, rcv)) {
|
||||
t.Errorf("Expecting: %v, received: %v", fp, rcv)
|
||||
}
|
||||
//get from database
|
||||
if rcv, err := GetFilter(onStor, "cgrates.org", "Filter1",
|
||||
if rcv, err := onStor.GetFilter("cgrates.org", "Filter1",
|
||||
false, false, utils.NonTransactional); err != nil {
|
||||
t.Error(err)
|
||||
} else if !(reflect.DeepEqual(fp, rcv)) {
|
||||
@@ -1738,12 +1738,12 @@ func testOnStorITFilter(t *testing.T) {
|
||||
t.Error(err)
|
||||
}
|
||||
//check cache if removed
|
||||
if _, rcvErr := GetFilter(onStor, "cgrates.org", "Filter1",
|
||||
if _, rcvErr := onStor.GetFilter("cgrates.org", "Filter1",
|
||||
true, false, utils.NonTransactional); rcvErr != nil && rcvErr != utils.ErrNotFound {
|
||||
t.Error(rcvErr)
|
||||
}
|
||||
//check database if removed
|
||||
if _, rcvErr := GetFilter(onStor, "cgrates.org", "Filter1",
|
||||
if _, rcvErr := onStor.GetFilter("cgrates.org", "Filter1",
|
||||
false, false, utils.NonTransactional); rcvErr != nil && rcvErr != utils.ErrNotFound {
|
||||
t.Error(rcvErr)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user