mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-11 18:16:24 +05:00
only one version structure in the db
This commit is contained in:
@@ -68,8 +68,6 @@ type RatingStorage interface {
|
||||
GetAllActionPlans() (map[string]*ActionPlan, error)
|
||||
PushTask(*Task) error
|
||||
PopTask() (*Task, error)
|
||||
GetRatingStructuresVersion() (*RatingStructuresVersion, error)
|
||||
SetRatingStructuresVersion(*RatingStructuresVersion) error
|
||||
}
|
||||
|
||||
type AccountingStorage interface {
|
||||
@@ -94,8 +92,8 @@ type AccountingStorage interface {
|
||||
RemoveAlias(string) error
|
||||
GetLoadHistory(int, bool) ([]*LoadInstance, error)
|
||||
AddLoadHistory(*LoadInstance, int) error
|
||||
GetAccountingStructuresVersion() (*AccountingStructuresVersion, error)
|
||||
SetAccountingStructuresVersion(*AccountingStructuresVersion) error
|
||||
GetStructVersion() (*StructVersion, error)
|
||||
SetStructVersion(*StructVersion) error
|
||||
}
|
||||
|
||||
type CdrStorage interface {
|
||||
@@ -104,8 +102,6 @@ type CdrStorage interface {
|
||||
SetSMCost(smc *SMCost) error
|
||||
GetSMCosts(cgrid, runid, originHost, originIDPrfx string) ([]*SMCost, error)
|
||||
GetCDRs(*utils.CDRsFilter, bool) ([]*CDR, int64, error)
|
||||
GetCdrStructuresVersion() (*CdrStructuresVersion, error)
|
||||
SetCdrStructuresVersion(*CdrStructuresVersion) error
|
||||
}
|
||||
|
||||
type LogStorage interface {
|
||||
|
||||
@@ -925,7 +925,7 @@ func (ms *MapStorage) LogActionTiming(source string, at *ActionTiming, as Action
|
||||
return
|
||||
}
|
||||
|
||||
func (ms *MapStorage) SetRatingStructuresVersion(v *RatingStructuresVersion) (err error) {
|
||||
func (ms *MapStorage) SetStructVersion(v *StructVersion) (err error) {
|
||||
ms.mu.Lock()
|
||||
defer ms.mu.Unlock()
|
||||
var result []byte
|
||||
@@ -933,65 +933,18 @@ func (ms *MapStorage) SetRatingStructuresVersion(v *RatingStructuresVersion) (er
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
ms.dict[utils.RATING_VERSION_PREFIX+"version"] = result
|
||||
ms.dict[utils.VERSION_PREFIX+"struct"] = result
|
||||
return
|
||||
}
|
||||
|
||||
func (ms *MapStorage) GetRatingStructuresVersion() (rsv *RatingStructuresVersion, err error) {
|
||||
func (ms *MapStorage) GetStructVersion() (rsv *StructVersion, err error) {
|
||||
ms.mu.RLock()
|
||||
defer ms.mu.RUnlock()
|
||||
rsv = &RatingStructuresVersion{}
|
||||
if values, ok := ms.dict[utils.RATING_VERSION_PREFIX+"version"]; ok {
|
||||
rsv = &StructVersion{}
|
||||
if values, ok := ms.dict[utils.VERSION_PREFIX+"struct"]; ok {
|
||||
err = ms.ms.Unmarshal(values, &rsv)
|
||||
} else {
|
||||
return nil, utils.ErrNotFound
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (ms *MapStorage) SetAccountingStructuresVersion(v *AccountingStructuresVersion) (err error) {
|
||||
ms.mu.Lock()
|
||||
defer ms.mu.Unlock()
|
||||
var result []byte
|
||||
result, err = ms.ms.Marshal(v)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
ms.dict[utils.ACCOUNTING_VERSION_PREFIX+"version"] = result
|
||||
return
|
||||
}
|
||||
|
||||
func (ms *MapStorage) GetAccountingStructuresVersion() (asv *AccountingStructuresVersion, err error) {
|
||||
ms.mu.RLock()
|
||||
defer ms.mu.RUnlock()
|
||||
asv = &AccountingStructuresVersion{}
|
||||
if values, ok := ms.dict[utils.ACCOUNTING_VERSION_PREFIX+"version"]; ok {
|
||||
err = ms.ms.Unmarshal(values, &asv)
|
||||
} else {
|
||||
return nil, utils.ErrNotFound
|
||||
}
|
||||
return
|
||||
}
|
||||
func (ms *MapStorage) SetCdrStructuresVersion(v *CdrStructuresVersion) (err error) {
|
||||
ms.mu.Lock()
|
||||
defer ms.mu.Unlock()
|
||||
var result []byte
|
||||
result, err = ms.ms.Marshal(v)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
ms.dict[utils.CDR_VERSION_PREFIX+"version"] = result
|
||||
return
|
||||
}
|
||||
|
||||
func (ms *MapStorage) GetCdrStructuresVersion() (csv *CdrStructuresVersion, err error) {
|
||||
ms.mu.RLock()
|
||||
defer ms.mu.RUnlock()
|
||||
csv = &CdrStructuresVersion{}
|
||||
if values, ok := ms.dict[utils.CDR_VERSION_PREFIX+"version"]; ok {
|
||||
err = ms.ms.Unmarshal(values, &csv)
|
||||
} else {
|
||||
return nil, utils.ErrNotFound
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
@@ -53,7 +53,7 @@ const (
|
||||
colLogAtr = "action_trigger_logs"
|
||||
colLogApl = "action_plan_logs"
|
||||
colLogErr = "error_logs"
|
||||
colVer = "versions"
|
||||
colVer = "version"
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -1365,53 +1365,19 @@ func (ms *MongoStorage) GetAllCdrStats() (css []*CdrStats, err error) {
|
||||
return
|
||||
}
|
||||
|
||||
func (ms *MongoStorage) SetRatingStructuresVersion(v *RatingStructuresVersion) (err error) {
|
||||
_, err = ms.db.C(colVer).Upsert(bson.M{"key": utils.RATING_VERSION_PREFIX + "version"}, &struct {
|
||||
func (ms *MongoStorage) SetStructVersion(v *StructVersion) (err error) {
|
||||
_, err = ms.db.C(colVer).Upsert(bson.M{"key": utils.VERSION_PREFIX + "struct"}, &struct {
|
||||
Key string
|
||||
Value *RatingStructuresVersion
|
||||
}{utils.RATING_VERSION_PREFIX + "version", v})
|
||||
Value *StructVersion
|
||||
}{utils.VERSION_PREFIX + "struct", v})
|
||||
return
|
||||
}
|
||||
|
||||
func (ms *MongoStorage) GetRatingStructuresVersion() (rsv *RatingStructuresVersion, err error) {
|
||||
rsv = new(RatingStructuresVersion)
|
||||
err = ms.db.C(colVer).Find(bson.M{"key": utils.RATING_VERSION_PREFIX + "version"}).One(rsv)
|
||||
func (ms *MongoStorage) GetStructVersion() (rsv *StructVersion, err error) {
|
||||
rsv = new(StructVersion)
|
||||
err = ms.db.C(colVer).Find(bson.M{"key": utils.VERSION_PREFIX + "struct"}).One(rsv)
|
||||
if err == mgo.ErrNotFound {
|
||||
rsv = nil
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (ms *MongoStorage) SetAccountingStructuresVersion(v *AccountingStructuresVersion) (err error) {
|
||||
_, err = ms.db.C(colVer).Upsert(bson.M{"key": utils.ACCOUNTING_VERSION_PREFIX + "version"}, &struct {
|
||||
Key string
|
||||
Value *AccountingStructuresVersion
|
||||
}{utils.ACCOUNTING_VERSION_PREFIX + "version", v})
|
||||
return
|
||||
}
|
||||
|
||||
func (ms *MongoStorage) GetAccountingStructuresVersion() (asv *AccountingStructuresVersion, err error) {
|
||||
asv = new(AccountingStructuresVersion)
|
||||
err = ms.db.C(colVer).Find(bson.M{"key": utils.ACCOUNTING_VERSION_PREFIX + "version"}).One(asv)
|
||||
if err == mgo.ErrNotFound {
|
||||
asv = nil
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (ms *MongoStorage) SetCdrStructuresVersion(v *CdrStructuresVersion) (err error) {
|
||||
_, err = ms.db.C(colVer).Upsert(bson.M{"key": utils.CDR_VERSION_PREFIX + "version"}, &struct {
|
||||
Key string
|
||||
Value *CdrStructuresVersion
|
||||
}{utils.CDR_VERSION_PREFIX + "version", v})
|
||||
return
|
||||
}
|
||||
|
||||
func (ms *MongoStorage) GetCdrStructuresVersion() (csv *CdrStructuresVersion, err error) {
|
||||
csv = new(CdrStructuresVersion)
|
||||
err = ms.db.C(colVer).Find(bson.M{"key": utils.CDR_VERSION_PREFIX + "version"}).One(csv)
|
||||
if err == mgo.ErrNotFound {
|
||||
csv = nil
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
@@ -1094,55 +1094,20 @@ func (rs *RedisStorage) LogActionTiming(source string, at *ActionTiming, as Acti
|
||||
return rs.db.Cmd("SET", utils.LOG_ACTION_TIMMING_PREFIX+source+"_"+time.Now().Format(time.RFC3339Nano), []byte(fmt.Sprintf("%v*%v", string(mat), string(mas)))).Err
|
||||
}
|
||||
|
||||
func (rs *RedisStorage) SetRatingStructuresVersion(v *RatingStructuresVersion) (err error) {
|
||||
func (rs *RedisStorage) SetStructVersion(v *StructVersion) (err error) {
|
||||
var result []byte
|
||||
result, err = rs.ms.Marshal(v)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
return rs.db.Cmd("SET", utils.RATING_VERSION_PREFIX+"version", result).Err
|
||||
return rs.db.Cmd("SET", utils.VERSION_PREFIX+"struct", result).Err
|
||||
}
|
||||
|
||||
func (rs *RedisStorage) GetRatingStructuresVersion() (rsv *RatingStructuresVersion, err error) {
|
||||
func (rs *RedisStorage) GetStructVersion() (rsv *StructVersion, err error) {
|
||||
var values []byte
|
||||
rsv = &RatingStructuresVersion{}
|
||||
if values, err = rs.db.Cmd("GET", utils.RATING_VERSION_PREFIX+"version").Bytes(); err == nil {
|
||||
rsv = &StructVersion{}
|
||||
if values, err = rs.db.Cmd("GET", utils.VERSION_PREFIX+"struct").Bytes(); err == nil {
|
||||
err = rs.ms.Unmarshal(values, &rsv)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (rs *RedisStorage) SetAccountingStructuresVersion(v *AccountingStructuresVersion) (err error) {
|
||||
var result []byte
|
||||
result, err = rs.ms.Marshal(v)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
return rs.db.Cmd("SET", utils.ACCOUNTING_VERSION_PREFIX+"version", result).Err
|
||||
}
|
||||
|
||||
func (rs *RedisStorage) GetAccountingStructuresVersion() (asv *AccountingStructuresVersion, err error) {
|
||||
var values []byte
|
||||
asv = &AccountingStructuresVersion{}
|
||||
if values, err = rs.db.Cmd("GET", utils.ACCOUNTING_VERSION_PREFIX+"version").Bytes(); err == nil {
|
||||
err = rs.ms.Unmarshal(values, &asv)
|
||||
}
|
||||
return
|
||||
}
|
||||
func (rs *RedisStorage) SetCdrStructuresVersion(v *CdrStructuresVersion) (err error) {
|
||||
var result []byte
|
||||
result, err = rs.ms.Marshal(v)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
return rs.db.Cmd("SET", utils.CDR_VERSION_PREFIX+"version", result).Err
|
||||
}
|
||||
|
||||
func (rs *RedisStorage) GetCdrStructuresVersion() (csv *CdrStructuresVersion, err error) {
|
||||
var values []byte
|
||||
csv = &CdrStructuresVersion{}
|
||||
if values, err = rs.db.Cmd("GET", utils.CDR_VERSION_PREFIX+"version").Bytes(); err == nil {
|
||||
err = rs.ms.Unmarshal(values, &csv)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
@@ -1343,11 +1343,3 @@ func (self *SQLStorage) GetTpAliases(filter *TpAlias) ([]TpAlias, error) {
|
||||
|
||||
return tpAliases, nil
|
||||
}
|
||||
|
||||
func (self *SQLStorage) SetCdrStructuresVersion(v *CdrStructuresVersion) (err error) {
|
||||
return utils.ErrNotImplemented
|
||||
}
|
||||
|
||||
func (self *SQLStorage) GetCdrStructuresVersion() (csv *CdrStructuresVersion, err error) {
|
||||
return nil, utils.ErrNotImplemented
|
||||
}
|
||||
|
||||
@@ -8,46 +8,22 @@ import (
|
||||
|
||||
func init() {
|
||||
// get current db version
|
||||
dbRsv, err := ratingStorage.GetRatingStructuresVersion()
|
||||
dbVersion, err := accountingStorage.GetStructVersion()
|
||||
if err != nil {
|
||||
utils.Logger.Warning(fmt.Sprintf("Could not retrive current version from db: %v", err))
|
||||
return
|
||||
}
|
||||
// comparing versions
|
||||
if currentRsv.CompareAndMigrate(dbRsv) {
|
||||
if currentVersion.CompareAndMigrate(dbVersion) {
|
||||
// write the new values
|
||||
if err := ratingStorage.SetRatingStructuresVersion(currentRsv); err != nil {
|
||||
utils.Logger.Warning(fmt.Sprintf("Could not write current version to db: %v", err))
|
||||
}
|
||||
}
|
||||
dbAsv, err := accountingStorage.GetAccountingStructuresVersion()
|
||||
if err != nil {
|
||||
utils.Logger.Warning(fmt.Sprintf("Could not retrive current version from db: %v", err))
|
||||
return
|
||||
}
|
||||
// comparing versions
|
||||
if currentAsv.CompareAndMigrate(dbAsv) {
|
||||
// write the new values
|
||||
if err := accountingStorage.SetAccountingStructuresVersion(currentAsv); err != nil {
|
||||
utils.Logger.Warning(fmt.Sprintf("Could not write current version to db: %v", err))
|
||||
}
|
||||
}
|
||||
dbCsv, err := cdrStorage.GetCdrStructuresVersion()
|
||||
if err != nil {
|
||||
utils.Logger.Warning(fmt.Sprintf("Could not retrive current version from db: %v", err))
|
||||
return
|
||||
}
|
||||
// comparing versions
|
||||
if currentCsv.CompareAndMigrate(dbCsv) {
|
||||
// write the new values
|
||||
if err := cdrStorage.SetCdrStructuresVersion(currentCsv); err != nil {
|
||||
if err := accountingStorage.SetStructVersion(currentVersion); err != nil {
|
||||
utils.Logger.Warning(fmt.Sprintf("Could not write current version to db: %v", err))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var (
|
||||
currentRsv = &RatingStructuresVersion{
|
||||
currentVersion = &StructVersion{
|
||||
Destinations: "1",
|
||||
RatingPlans: "1",
|
||||
RatingProfiles: "1",
|
||||
@@ -57,24 +33,19 @@ var (
|
||||
ActionPlans: "1",
|
||||
ActionTriggers: "1",
|
||||
SharedGroups: "1",
|
||||
}
|
||||
|
||||
currentAsv = &AccountingStructuresVersion{
|
||||
Accounts: "1",
|
||||
CdrStats: "1",
|
||||
Users: "1",
|
||||
Alias: "1",
|
||||
PubSubs: "1",
|
||||
LoadHistory: "1",
|
||||
}
|
||||
|
||||
currentCsv = &CdrStructuresVersion{
|
||||
Cdrs: "1",
|
||||
SMCosts: "1",
|
||||
Accounts: "1",
|
||||
CdrStats: "1",
|
||||
Users: "1",
|
||||
Alias: "1",
|
||||
PubSubs: "1",
|
||||
LoadHistory: "1",
|
||||
Cdrs: "1",
|
||||
SMCosts: "1",
|
||||
}
|
||||
)
|
||||
|
||||
type RatingStructuresVersion struct {
|
||||
type StructVersion struct {
|
||||
// rating
|
||||
Destinations string
|
||||
RatingPlans string
|
||||
RatingProfiles string
|
||||
@@ -84,92 +55,78 @@ type RatingStructuresVersion struct {
|
||||
ActionPlans string
|
||||
ActionTriggers string
|
||||
SharedGroups string
|
||||
}
|
||||
|
||||
func (rsv *RatingStructuresVersion) CompareAndMigrate(dbRsv *RatingStructuresVersion) bool {
|
||||
migrationPerformed := false
|
||||
if rsv.Destinations != dbRsv.Destinations {
|
||||
migrationPerformed = true
|
||||
|
||||
}
|
||||
if rsv.RatingPlans != dbRsv.RatingPlans {
|
||||
migrationPerformed = true
|
||||
|
||||
}
|
||||
if rsv.RatingProfiles != dbRsv.RatingPlans {
|
||||
migrationPerformed = true
|
||||
|
||||
}
|
||||
if rsv.Lcrs != dbRsv.Lcrs {
|
||||
migrationPerformed = true
|
||||
|
||||
}
|
||||
if rsv.DerivedChargers != dbRsv.DerivedChargers {
|
||||
migrationPerformed = true
|
||||
|
||||
}
|
||||
if rsv.Actions != dbRsv.Actions {
|
||||
migrationPerformed = true
|
||||
|
||||
}
|
||||
if rsv.ActionPlans != dbRsv.ActionPlans {
|
||||
migrationPerformed = true
|
||||
|
||||
}
|
||||
if rsv.ActionTriggers != dbRsv.ActionTriggers {
|
||||
migrationPerformed = true
|
||||
|
||||
}
|
||||
if rsv.SharedGroups != dbRsv.SharedGroups {
|
||||
migrationPerformed = true
|
||||
|
||||
}
|
||||
return migrationPerformed
|
||||
}
|
||||
|
||||
type AccountingStructuresVersion struct {
|
||||
// accounting
|
||||
Accounts string
|
||||
CdrStats string
|
||||
Users string
|
||||
Alias string
|
||||
PubSubs string
|
||||
LoadHistory string
|
||||
}
|
||||
|
||||
func (asv *AccountingStructuresVersion) CompareAndMigrate(dbAsv *AccountingStructuresVersion) bool {
|
||||
migrationPerformed := false
|
||||
if asv.Accounts != dbAsv.Accounts {
|
||||
migrationPerformed = true
|
||||
}
|
||||
if asv.CdrStats != dbAsv.CdrStats {
|
||||
migrationPerformed = true
|
||||
}
|
||||
if asv.Users != dbAsv.Users {
|
||||
migrationPerformed = true
|
||||
}
|
||||
if asv.Alias != dbAsv.Alias {
|
||||
migrationPerformed = true
|
||||
}
|
||||
if asv.PubSubs != dbAsv.PubSubs {
|
||||
migrationPerformed = true
|
||||
}
|
||||
if asv.LoadHistory != dbAsv.LoadHistory {
|
||||
migrationPerformed = true
|
||||
}
|
||||
return migrationPerformed
|
||||
}
|
||||
|
||||
type CdrStructuresVersion struct {
|
||||
// cdr
|
||||
Cdrs string
|
||||
SMCosts string
|
||||
}
|
||||
|
||||
func (csv *CdrStructuresVersion) CompareAndMigrate(dbCsv *CdrStructuresVersion) bool {
|
||||
func (sv *StructVersion) CompareAndMigrate(dbVer *StructVersion) bool {
|
||||
migrationPerformed := false
|
||||
if csv.Cdrs != dbCsv.Cdrs {
|
||||
if sv.Destinations != dbVer.Destinations {
|
||||
migrationPerformed = true
|
||||
|
||||
}
|
||||
if sv.RatingPlans != dbVer.RatingPlans {
|
||||
migrationPerformed = true
|
||||
|
||||
}
|
||||
if sv.RatingProfiles != dbVer.RatingPlans {
|
||||
migrationPerformed = true
|
||||
|
||||
}
|
||||
if sv.Lcrs != dbVer.Lcrs {
|
||||
migrationPerformed = true
|
||||
|
||||
}
|
||||
if sv.DerivedChargers != dbVer.DerivedChargers {
|
||||
migrationPerformed = true
|
||||
|
||||
}
|
||||
if sv.Actions != dbVer.Actions {
|
||||
migrationPerformed = true
|
||||
|
||||
}
|
||||
if sv.ActionPlans != dbVer.ActionPlans {
|
||||
migrationPerformed = true
|
||||
|
||||
}
|
||||
if sv.ActionTriggers != dbVer.ActionTriggers {
|
||||
migrationPerformed = true
|
||||
|
||||
}
|
||||
if sv.SharedGroups != dbVer.SharedGroups {
|
||||
migrationPerformed = true
|
||||
|
||||
}
|
||||
if sv.Accounts != dbVer.Accounts {
|
||||
migrationPerformed = true
|
||||
}
|
||||
if csv.SMCosts != dbCsv.SMCosts {
|
||||
if sv.CdrStats != dbVer.CdrStats {
|
||||
migrationPerformed = true
|
||||
}
|
||||
if sv.Users != dbVer.Users {
|
||||
migrationPerformed = true
|
||||
}
|
||||
if sv.Alias != dbVer.Alias {
|
||||
migrationPerformed = true
|
||||
}
|
||||
if sv.PubSubs != dbVer.PubSubs {
|
||||
migrationPerformed = true
|
||||
}
|
||||
if sv.LoadHistory != dbVer.LoadHistory {
|
||||
migrationPerformed = true
|
||||
}
|
||||
if sv.Cdrs != dbVer.Cdrs {
|
||||
migrationPerformed = true
|
||||
}
|
||||
if sv.SMCosts != dbVer.SMCosts {
|
||||
migrationPerformed = true
|
||||
}
|
||||
return migrationPerformed
|
||||
|
||||
@@ -197,9 +197,7 @@ const (
|
||||
LOG_CALL_COST_PREFIX = "cco_"
|
||||
LOG_ACTION_TIMMING_PREFIX = "ltm_"
|
||||
LOG_ACTION_TRIGGER_PREFIX = "ltr_"
|
||||
RATING_VERSION_PREFIX = "rve_"
|
||||
ACCOUNTING_VERSION_PREFIX = "ave_"
|
||||
CDR_VERSION_PREFIX = "cve_"
|
||||
VERSION_PREFIX = "ver_"
|
||||
LOG_ERR = "ler_"
|
||||
LOG_CDR = "cdr_"
|
||||
LOG_MEDIATED_CDR = "mcd_"
|
||||
|
||||
Reference in New Issue
Block a user