mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-11 18:16:24 +05:00
Add infrastructure for AccountS in LoaderS
This commit is contained in:
committed by
Dan Christian Bogos
parent
aca6323c6f
commit
fd3defa7ef
19
dispatchers/accounts.go
Normal file
19
dispatchers/accounts.go
Normal file
@@ -0,0 +1,19 @@
|
||||
/*
|
||||
Real-time Online/Offline Charging System (OCS) for Telecom & ISP environments
|
||||
Copyright (C) ITsysCOM GmbH
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
*/
|
||||
|
||||
package dispatchers
|
||||
@@ -4027,7 +4027,7 @@ func (dm *DataManager) SetAccount2(ap *utils.Account, withIndex bool) (err error
|
||||
}
|
||||
|
||||
func (dm *DataManager) RemoveAccount2(tenant, id string,
|
||||
transactionID string, withIndex bool) (err error) {
|
||||
transactionID string) (err error) {
|
||||
if dm == nil {
|
||||
err = utils.ErrNoDatabaseConn
|
||||
return
|
||||
|
||||
@@ -652,6 +652,36 @@ func (ldr *Loader) storeLoadedData(loaderType string,
|
||||
cacheArgs[utils.ActionProfileIDs] = ids
|
||||
}
|
||||
}
|
||||
case utils.MetaAccountProfiles:
|
||||
cacheIDs = []string{utils.CacheAccountProfilesFilterIndexes}
|
||||
for _, lDataSet := range lds {
|
||||
acpsModels := make(engine.AccountProfileMdls, len(lDataSet))
|
||||
for i, ld := range lDataSet {
|
||||
acpsModels[i] = new(engine.AccountProfileMdl)
|
||||
if err = utils.UpdateStructWithIfaceMap(acpsModels[i], ld); err != nil {
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
for _, tpAcp := range acpsModels.AsTPAccountProfile() {
|
||||
acp, err := engine.APItoAccountProfile(tpAcp, ldr.timezone)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if ldr.dryRun {
|
||||
utils.Logger.Info(
|
||||
fmt.Sprintf("<%s-%s> DRY_RUN: AccountProfiles: %s",
|
||||
utils.LoaderS, ldr.ldrID, utils.ToJSON(acp)))
|
||||
continue
|
||||
}
|
||||
// get IDs so we can reload in cache
|
||||
ids = append(ids, acp.TenantID())
|
||||
if err := ldr.dm.SetAccountProfile(acp, true); err != nil {
|
||||
return err
|
||||
}
|
||||
cacheArgs[utils.AccountProfileIDs] = ids
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if len(ldr.cacheConns) != 0 {
|
||||
@@ -992,6 +1022,28 @@ func (ldr *Loader) removeLoadedData(loaderType string, lds map[string][]LoaderDa
|
||||
cacheArgs[utils.ActionProfileIDs] = ids
|
||||
}
|
||||
}
|
||||
case utils.MetaAccountProfiles:
|
||||
cacheIDs = []string{utils.CacheAccountProfiles, utils.CacheAccounts2, utils.CacheAccountProfilesFilterIndexes}
|
||||
for tntID := range lds {
|
||||
if ldr.dryRun {
|
||||
utils.Logger.Info(
|
||||
fmt.Sprintf("<%s-%s> DRY_RUN: AccountProfileIDs: %s",
|
||||
utils.LoaderS, ldr.ldrID, tntID))
|
||||
} else {
|
||||
tntIDStruct := utils.NewTenantID(tntID)
|
||||
// get IDs so we can reload in cache
|
||||
ids = append(ids, tntID)
|
||||
if err := ldr.dm.RemoveAccountProfile(tntIDStruct.Tenant,
|
||||
tntIDStruct.ID, utils.NonTransactional, true); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := ldr.dm.RemoveAccount2(tntIDStruct.Tenant, tntIDStruct.ID, utils.NonTransactional); err != nil {
|
||||
return err
|
||||
}
|
||||
cacheArgs[utils.AccountProfileIDs] = ids
|
||||
cacheArgs[utils.Account2IDs] = ids
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if len(ldr.cacheConns) != 0 {
|
||||
|
||||
@@ -2597,6 +2597,7 @@ const (
|
||||
ActionProfileIDs = "ActionProfileIDs"
|
||||
TimingIDs = "TimingIDs"
|
||||
AccountProfileIDs = "AccountProfileIDs"
|
||||
Account2IDs = "Account2IDs"
|
||||
AttributeFilterIndexIDs = "AttributeFilterIndexIDs"
|
||||
ResourceFilterIndexIDs = "ResourceFilterIndexIDs"
|
||||
StatFilterIndexIDs = "StatFilterIndexIDs"
|
||||
|
||||
Reference in New Issue
Block a user