mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-11 18:16:24 +05:00
ips: move ComputeUnexported to DataManager
This commit is contained in:
committed by
Dan Christian Bogos
parent
d76759ea5b
commit
f5be437711
@@ -170,7 +170,7 @@ func (dm *DataManager) CacheDataFromDB(ctx *context.Context, prfx string, ids []
|
||||
case utils.IPAllocationsPrefix:
|
||||
tntID := utils.NewTenantID(dataID)
|
||||
lkID := guardian.Guardian.GuardIDs("", dm.cfg.GeneralCfg().LockingTimeout, utils.IPAllocationsLockKey(tntID.Tenant, tntID.ID))
|
||||
_, err = dm.GetIPAllocations(ctx, tntID.Tenant, tntID.ID, false, true, utils.NonTransactional)
|
||||
_, err = dm.GetIPAllocations(ctx, tntID.Tenant, tntID.ID, false, true, utils.NonTransactional, nil)
|
||||
guardian.Guardian.UnguardIDs(lkID)
|
||||
case utils.StatQueueProfilePrefix:
|
||||
tntID := utils.NewTenantID(dataID)
|
||||
@@ -1684,7 +1684,7 @@ func (dm *DataManager) RemoveResourceProfile(ctx *context.Context, tenant, id st
|
||||
}
|
||||
|
||||
func (dm *DataManager) GetIPAllocations(ctx *context.Context, tenant, id string, cacheRead, cacheWrite bool,
|
||||
transactionID string) (ip *utils.IPAllocations, err error) {
|
||||
transactionID string, prfl *utils.IPProfile) (ip *utils.IPAllocations, err error) {
|
||||
tntID := utils.ConcatenatedKey(tenant, id)
|
||||
if cacheRead {
|
||||
if x, ok := Cache.Get(utils.CacheIPAllocations, tntID); ok {
|
||||
@@ -1724,6 +1724,11 @@ func (dm *DataManager) GetIPAllocations(ctx *context.Context, tenant, id string,
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
if prfl != nil {
|
||||
if err = ip.ComputeUnexported(prfl); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
if cacheWrite {
|
||||
if errCh := Cache.Set(ctx, utils.CacheIPAllocations, tntID, ip, nil,
|
||||
cacheCommit(transactionID), transactionID); errCh != nil {
|
||||
@@ -1871,8 +1876,8 @@ func (dm *DataManager) SetIPProfile(ctx *context.Context, ipp *utils.IPProfile,
|
||||
ID: ipp.ID,
|
||||
Allocations: make(map[string]*utils.PoolAllocation),
|
||||
})
|
||||
} else if _, errRs := dm.GetIPAllocations(ctx, ipp.Tenant, ipp.ID, // do not try to get the resource if the configuration changed
|
||||
true, false, utils.NonTransactional); errRs == utils.ErrNotFound { // the resource does not exist
|
||||
} else if _, errGet := dm.GetIPAllocations(ctx, ipp.Tenant, ipp.ID, // do not try to get the resource if the configuration changed
|
||||
true, false, utils.NonTransactional, nil); errGet == utils.ErrNotFound { // the resource does not exist
|
||||
err = dm.SetIPAllocations(ctx, &utils.IPAllocations{
|
||||
Tenant: ipp.Tenant,
|
||||
ID: ipp.ID,
|
||||
|
||||
@@ -291,7 +291,7 @@ func (s *IPService) V1GetIPAllocations(ctx *context.Context, arg *utils.TenantID
|
||||
utils.IPAllocationsLockKey(tnt, arg.ID))
|
||||
defer guardian.Guardian.UnguardIDs(lkID)
|
||||
|
||||
ip, err := s.dm.GetIPAllocations(ctx, tnt, arg.ID, true, true, utils.NonTransactional)
|
||||
ip, err := s.dm.GetIPAllocations(ctx, tnt, arg.ID, true, true, utils.NonTransactional, nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -260,17 +260,13 @@ func (s *IPService) matchingIPAllocationsForEvent(ctx *context.Context, tnt stri
|
||||
lkID := guardian.Guardian.GuardIDs(utils.EmptyString,
|
||||
config.CgrConfig().GeneralCfg().LockingTimeout,
|
||||
utils.IPAllocationsLockKey(matchedPrfl.Tenant, matchedPrfl.ID))
|
||||
allocs, err = s.dm.GetIPAllocations(ctx, matchedPrfl.Tenant, matchedPrfl.ID, true, true, "")
|
||||
allocs, err = s.dm.GetIPAllocations(ctx, matchedPrfl.Tenant, matchedPrfl.ID, true, true, "", matchedPrfl)
|
||||
if err != nil {
|
||||
guardian.Guardian.UnguardIDs(lkID)
|
||||
matchedPrfl.Unlock()
|
||||
return nil, err
|
||||
}
|
||||
allocs.Lock(lkID)
|
||||
if err = allocs.ComputeUnexported(matchedPrfl); err != nil {
|
||||
allocs.Unlock()
|
||||
return nil, err
|
||||
}
|
||||
if err = engine.Cache.Set(ctx, utils.CacheEventIPs, evUUID,
|
||||
|
||||
// TODO: check if we still should rely on caching previously matched
|
||||
|
||||
Reference in New Issue
Block a user