mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-11 18:16:24 +05:00
fixes for local tests
This commit is contained in:
@@ -72,7 +72,7 @@ func (self *ApierV1) RemRatingSubjectAliases(tenantRatingSubject engine.TenantRa
|
||||
if missing := utils.MissingStructFields(&tenantRatingSubject, []string{"Tenant", "Subject"}); len(missing) != 0 {
|
||||
return utils.NewErrMandatoryIeMissing(missing...)
|
||||
}
|
||||
if err := self.RatingDb.RemoveRpAliases([]*engine.TenantRatingSubject{&tenantRatingSubject}); err != nil {
|
||||
if err := self.RatingDb.RemoveRpAliases([]*engine.TenantRatingSubject{&tenantRatingSubject}, false); err != nil {
|
||||
if err == utils.ErrNotFound {
|
||||
return err
|
||||
}
|
||||
@@ -125,7 +125,7 @@ func (self *ApierV1) RemAccountAliases(tenantAccount engine.TenantAccount, reply
|
||||
if missing := utils.MissingStructFields(&tenantAccount, []string{"Tenant", "Account"}); len(missing) != 0 {
|
||||
return utils.NewErrMandatoryIeMissing(missing...)
|
||||
}
|
||||
if err := self.RatingDb.RemoveAccAliases([]*engine.TenantAccount{&tenantAccount}); err != nil {
|
||||
if err := self.RatingDb.RemoveAccAliases([]*engine.TenantAccount{&tenantAccount}, false); err != nil {
|
||||
if err == utils.ErrNotFound {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -49,7 +49,7 @@ type RatingStorage interface {
|
||||
SetRatingProfile(*RatingProfile) error
|
||||
GetRpAlias(string, bool) (string, error)
|
||||
SetRpAlias(string, string) error
|
||||
RemoveRpAliases([]*TenantRatingSubject) error
|
||||
RemoveRpAliases([]*TenantRatingSubject, bool) error
|
||||
GetRPAliases(string, string, bool) ([]string, error)
|
||||
GetDestination(string) (*Destination, error)
|
||||
SetDestination(*Destination) error
|
||||
@@ -69,7 +69,7 @@ type RatingStorage interface {
|
||||
GetAllActionPlans() (map[string]ActionPlans, error)
|
||||
GetAccAlias(string, bool) (string, error)
|
||||
SetAccAlias(string, string) error
|
||||
RemoveAccAliases([]*TenantAccount) error
|
||||
RemoveAccAliases([]*TenantAccount, bool) error
|
||||
GetAccountAliases(string, string, bool) ([]string, error)
|
||||
SetUser(*UserProfile) error
|
||||
GetUser(string) (*UserProfile, error)
|
||||
|
||||
@@ -342,18 +342,30 @@ func (ms *MapStorage) SetRpAlias(key, alias string) (err error) {
|
||||
return
|
||||
}
|
||||
|
||||
func (ms *MapStorage) RemoveRpAliases(tenantRtSubjects []*TenantRatingSubject) (err error) {
|
||||
for key, _ := range ms.dict {
|
||||
for _, tntRtSubj := range tenantRtSubjects {
|
||||
tenantPrfx := utils.RP_ALIAS_PREFIX + tntRtSubj.Tenant + utils.CONCATENATED_KEY_SEP
|
||||
if strings.HasPrefix(key, utils.RP_ALIAS_PREFIX) {
|
||||
alsSubj, err := ms.GetRpAlias(key[len(utils.RP_ALIAS_PREFIX):], true)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if len(key) >= len(tenantPrfx) && key[:len(tenantPrfx)] == tenantPrfx && tntRtSubj.Subject == alsSubj {
|
||||
cache2go.RemKey(key)
|
||||
func (ms *MapStorage) RemoveRpAliases(tenantRtSubjects []*TenantRatingSubject, skipCache bool) (err error) {
|
||||
if skipCache {
|
||||
for key, value := range ms.dict {
|
||||
for _, tenantRtSubj := range tenantRtSubjects {
|
||||
tenantPrfx := utils.RP_ALIAS_PREFIX + tenantRtSubj.Tenant + utils.CONCATENATED_KEY_SEP
|
||||
if strings.HasPrefix(key, utils.RP_ALIAS_PREFIX) && len(key) >= len(tenantPrfx) && key[:len(tenantPrfx)] == tenantPrfx && tenantRtSubj.Subject == string(value) {
|
||||
delete(ms.dict, key)
|
||||
cache2go.RemKey(key)
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
alsMap, err := cache2go.GetAllEntries(utils.RP_ALIAS_PREFIX)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
for key, aliasInterface := range alsMap {
|
||||
alias := aliasInterface.Value().(string)
|
||||
for _, tenantRtSubj := range tenantRtSubjects {
|
||||
tenantPrfx := tenantRtSubj.Tenant + utils.CONCATENATED_KEY_SEP
|
||||
if len(key) >= len(tenantPrfx) && key[:len(tenantPrfx)] == tenantPrfx && tenantRtSubj.Subject == alias {
|
||||
delete(ms.dict, utils.RP_ALIAS_PREFIX+key)
|
||||
cache2go.RemKey(utils.RP_ALIAS_PREFIX + key)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -408,12 +420,31 @@ func (ms *MapStorage) SetAccAlias(key, alias string) (err error) {
|
||||
return
|
||||
}
|
||||
|
||||
func (ms *MapStorage) RemoveAccAliases(tenantAccounts []*TenantAccount) (err error) {
|
||||
for key, value := range ms.dict {
|
||||
for _, tntAcnt := range tenantAccounts {
|
||||
tenantPrfx := utils.ACC_ALIAS_PREFIX + tntAcnt.Tenant + utils.CONCATENATED_KEY_SEP
|
||||
if strings.HasPrefix(key, utils.ACC_ALIAS_PREFIX) && len(key) >= len(tenantPrfx) && key[:len(tenantPrfx)] == tenantPrfx && tntAcnt.Account == string(value) {
|
||||
delete(ms.dict, key)
|
||||
func (ms *MapStorage) RemoveAccAliases(tenantAccounts []*TenantAccount, skipCache bool) (err error) {
|
||||
if skipCache {
|
||||
for key, value := range ms.dict {
|
||||
for _, tntAcnt := range tenantAccounts {
|
||||
tenantPrfx := utils.ACC_ALIAS_PREFIX + tntAcnt.Tenant + utils.CONCATENATED_KEY_SEP
|
||||
if strings.HasPrefix(key, utils.ACC_ALIAS_PREFIX) && len(key) >= len(tenantPrfx) && key[:len(tenantPrfx)] == tenantPrfx && tntAcnt.Account == string(value) {
|
||||
delete(ms.dict, key)
|
||||
cache2go.RemKey(key)
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
alsMap, err := cache2go.GetAllEntries(utils.ACC_ALIAS_PREFIX)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
for key, aliasInterface := range alsMap {
|
||||
alias := aliasInterface.Value().(string)
|
||||
for _, tntAcnt := range tenantAccounts {
|
||||
tenantPrfx := tntAcnt.Tenant + utils.CONCATENATED_KEY_SEP
|
||||
if len(key) >= len(tenantPrfx) && key[:len(tenantPrfx)] == tenantPrfx && tntAcnt.Account == alias {
|
||||
delete(ms.dict, utils.ACC_ALIAS_PREFIX+key)
|
||||
cache2go.RemKey(utils.ACC_ALIAS_PREFIX + key)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -411,28 +411,56 @@ func (rs *RedisStorage) SetRpAlias(key, alias string) (err error) {
|
||||
}
|
||||
|
||||
// Removes the aliases of a specific account, on a tenant
|
||||
func (rs *RedisStorage) RemoveRpAliases(tenantRtSubjects []*TenantRatingSubject) (err error) {
|
||||
alsMap, err := cache2go.GetAllEntries(utils.RP_ALIAS_PREFIX)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
for key, aliasInterface := range alsMap {
|
||||
alias := aliasInterface.Value().(string)
|
||||
for _, tntRSubj := range tenantRtSubjects {
|
||||
tenantPrfx := tntRSubj.Tenant + utils.CONCATENATED_KEY_SEP
|
||||
if len(key) < len(tenantPrfx) || !strings.HasPrefix(key, tenantPrfx) { // filter out the tenant for accounts
|
||||
continue
|
||||
}
|
||||
if tntRSubj.Subject != alias {
|
||||
continue
|
||||
}
|
||||
if _, err = rs.db.Del(utils.RP_ALIAS_PREFIX + key); err != nil {
|
||||
return err
|
||||
}
|
||||
cache2go.RemKey(utils.RP_ALIAS_PREFIX + key)
|
||||
break
|
||||
func (rs *RedisStorage) RemoveRpAliases(tenantRtSubjects []*TenantRatingSubject, skipCache bool) (err error) {
|
||||
if skipCache {
|
||||
alsKeys, err := rs.db.Keys(utils.RP_ALIAS_PREFIX + "*")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
for _, key := range alsKeys {
|
||||
for _, tntRSubj := range tenantRtSubjects {
|
||||
tenantPrfx := utils.RP_ALIAS_PREFIX + tntRSubj.Tenant + utils.CONCATENATED_KEY_SEP
|
||||
if len(key) < len(tenantPrfx) || tenantPrfx != key[:len(tenantPrfx)] { // filter out the tenant for accounts
|
||||
continue
|
||||
}
|
||||
alias, err := rs.GetRpAlias(key[len(utils.RP_ALIAS_PREFIX):], true)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if tntRSubj.Subject != alias {
|
||||
continue
|
||||
}
|
||||
cache2go.RemKey(key)
|
||||
if _, err = rs.db.Del(key); err != nil {
|
||||
return err
|
||||
}
|
||||
break
|
||||
}
|
||||
}
|
||||
} else {
|
||||
alsMap, err := cache2go.GetAllEntries(utils.RP_ALIAS_PREFIX)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
for key, aliasInterface := range alsMap {
|
||||
alias := aliasInterface.Value().(string)
|
||||
for _, tntRSubj := range tenantRtSubjects {
|
||||
tenantPrfx := tntRSubj.Tenant + utils.CONCATENATED_KEY_SEP
|
||||
if len(key) < len(tenantPrfx) || !strings.HasPrefix(key, tenantPrfx) { // filter out the tenant for accounts
|
||||
continue
|
||||
}
|
||||
if tntRSubj.Subject != alias {
|
||||
continue
|
||||
}
|
||||
if _, err = rs.db.Del(utils.RP_ALIAS_PREFIX + key); err != nil {
|
||||
return err
|
||||
}
|
||||
cache2go.RemKey(utils.RP_ALIAS_PREFIX + key)
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
return
|
||||
}
|
||||
@@ -506,26 +534,53 @@ func (rs *RedisStorage) SetAccAlias(key, alias string) (err error) {
|
||||
return
|
||||
}
|
||||
|
||||
func (rs *RedisStorage) RemoveAccAliases(tenantAccounts []*TenantAccount) (err error) {
|
||||
alsMap, err := cache2go.GetAllEntries(utils.ACC_ALIAS_PREFIX)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
func (rs *RedisStorage) RemoveAccAliases(tenantAccounts []*TenantAccount, skipCache bool) (err error) {
|
||||
if skipCache {
|
||||
alsKeys, err := rs.db.Keys(utils.ACC_ALIAS_PREFIX + "*")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
for _, key := range alsKeys {
|
||||
for _, tntAcnt := range tenantAccounts {
|
||||
tenantPrfx := utils.ACC_ALIAS_PREFIX + tntAcnt.Tenant + utils.CONCATENATED_KEY_SEP
|
||||
if len(key) < len(tenantPrfx) || tenantPrfx != key[:len(tenantPrfx)] { // filter out the tenant for accounts
|
||||
continue
|
||||
}
|
||||
alias, err := rs.GetAccAlias(key[len(utils.ACC_ALIAS_PREFIX):], true)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if tntAcnt.Account != alias {
|
||||
continue
|
||||
}
|
||||
cache2go.RemKey(key)
|
||||
if _, err = rs.db.Del(key); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for key, aliasInterface := range alsMap {
|
||||
alias := aliasInterface.Value().(string)
|
||||
for _, tntAcnt := range tenantAccounts {
|
||||
tenantPrfx := tntAcnt.Tenant + utils.CONCATENATED_KEY_SEP
|
||||
if len(key) < len(tenantPrfx) || !strings.HasPrefix(key, tenantPrfx) { // filter out the tenant for accounts
|
||||
continue
|
||||
} else {
|
||||
alsMap, err := cache2go.GetAllEntries(utils.ACC_ALIAS_PREFIX)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
for key, aliasInterface := range alsMap {
|
||||
alias := aliasInterface.Value().(string)
|
||||
for _, tntAcnt := range tenantAccounts {
|
||||
tenantPrfx := tntAcnt.Tenant + utils.CONCATENATED_KEY_SEP
|
||||
if len(key) < len(tenantPrfx) || !strings.HasPrefix(key, tenantPrfx) { // filter out the tenant for accounts
|
||||
continue
|
||||
}
|
||||
if tntAcnt.Account != alias {
|
||||
continue
|
||||
}
|
||||
if _, err = rs.db.Del(utils.ACC_ALIAS_PREFIX + key); err != nil {
|
||||
return err
|
||||
}
|
||||
cache2go.RemKey(utils.ACC_ALIAS_PREFIX + key)
|
||||
}
|
||||
if tntAcnt.Account != alias {
|
||||
continue
|
||||
}
|
||||
if _, err = rs.db.Del(utils.ACC_ALIAS_PREFIX + key); err != nil {
|
||||
return err
|
||||
}
|
||||
cache2go.RemKey(utils.ACC_ALIAS_PREFIX + key)
|
||||
}
|
||||
}
|
||||
return
|
||||
|
||||
@@ -159,7 +159,7 @@ func TestRemRSubjAliases(t *testing.T) {
|
||||
if err := ratingStorage.SetRpAlias(utils.RatingSubjectAliasKey("itsyscom.com", "2003"), "1001"); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
if err := ratingStorage.RemoveRpAliases([]*TenantRatingSubject{&TenantRatingSubject{Tenant: "cgrates.org", Subject: "1001"}}); err != nil {
|
||||
if err := ratingStorage.RemoveRpAliases([]*TenantRatingSubject{&TenantRatingSubject{Tenant: "cgrates.org", Subject: "1001"}}, true); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
if cgrAliases, err := ratingStorage.GetRPAliases("cgrates.org", "1001", true); err != nil {
|
||||
@@ -184,7 +184,7 @@ func TestStorageRpAliases(t *testing.T) {
|
||||
if _, err := ratingStorage.GetRpAlias("cgrates.org:1991", true); err != nil {
|
||||
t.Error("Alias not found after setting")
|
||||
}
|
||||
if err := ratingStorage.RemoveRpAliases([]*TenantRatingSubject{&TenantRatingSubject{Tenant: "cgrates.org", Subject: "1991"}}); err != nil {
|
||||
if err := ratingStorage.RemoveRpAliases([]*TenantRatingSubject{&TenantRatingSubject{Tenant: "cgrates.org", Subject: "1991"}}, true); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
if _, err := ratingStorage.GetRpAlias("cgrates.org:1991", true); err == nil {
|
||||
@@ -225,7 +225,7 @@ func TestStorageAccAliases(t *testing.T) {
|
||||
if _, err := ratingStorage.GetAccAlias("cgrates.org:1991", true); err != nil {
|
||||
t.Error("Alias not found after setting")
|
||||
}
|
||||
if err := ratingStorage.RemoveAccAliases([]*TenantAccount{&TenantAccount{Tenant: "cgrates.org", Account: "1991"}}); err != nil {
|
||||
if err := ratingStorage.RemoveAccAliases([]*TenantAccount{&TenantAccount{Tenant: "cgrates.org", Account: "1991"}}, true); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
if _, err := ratingStorage.GetAccAlias("cgrates.org:1991", true); err == nil {
|
||||
|
||||
@@ -1251,7 +1251,7 @@ func (tpr *TpReader) WriteToDatabase(flush, verbose bool) (err error) {
|
||||
if verbose {
|
||||
log.Print("Rating Profile Aliases:")
|
||||
}
|
||||
if err := tpr.ratingStorage.RemoveRpAliases(tpr.dirtyRpAliases); err != nil {
|
||||
if err := tpr.ratingStorage.RemoveRpAliases(tpr.dirtyRpAliases, true); err != nil {
|
||||
return err
|
||||
}
|
||||
for key, alias := range tpr.rpAliases {
|
||||
@@ -1266,7 +1266,7 @@ func (tpr *TpReader) WriteToDatabase(flush, verbose bool) (err error) {
|
||||
if verbose {
|
||||
log.Print("Account Aliases:")
|
||||
}
|
||||
if err := tpr.ratingStorage.RemoveAccAliases(tpr.dirtyAccAliases); err != nil {
|
||||
if err := tpr.ratingStorage.RemoveAccAliases(tpr.dirtyAccAliases, true); err != nil {
|
||||
return err
|
||||
}
|
||||
for key, alias := range tpr.accAliases {
|
||||
|
||||
Reference in New Issue
Block a user