diff --git a/engine/storage_interface.go b/engine/storage_interface.go index 03a6f65a8..bc845ed95 100644 --- a/engine/storage_interface.go +++ b/engine/storage_interface.go @@ -130,6 +130,7 @@ type DataDB interface { RemoveDispatcherProfileDrv(string, string) error GetItemLoadIDsDrv(itemIDPrefix string) (loadIDs map[string]int64, err error) SetLoadIDsDrv(loadIDs map[string]int64) error + RemoveLoadIDsDrv() error GetDispatcherHostDrv(string, string) (*DispatcherHost, error) SetDispatcherHostDrv(*DispatcherHost) error RemoveDispatcherHostDrv(string, string) error diff --git a/engine/storage_internal_datadb.go b/engine/storage_internal_datadb.go index b8103d9bb..63b5aedd8 100644 --- a/engine/storage_internal_datadb.go +++ b/engine/storage_internal_datadb.go @@ -1049,3 +1049,7 @@ func (iDB *InternalDB) RemoveDispatcherHostDrv(tenant, id string) (err error) { cacheCommit(utils.NonTransactional), utils.NonTransactional) return } + +func (iDB *InternalDB) RemoveLoadIDsDrv() (err error) { + return utils.ErrNotImplemented +} diff --git a/engine/storage_map_datadb.go b/engine/storage_map_datadb.go index 485357a04..dad222ae2 100644 --- a/engine/storage_map_datadb.go +++ b/engine/storage_map_datadb.go @@ -1451,3 +1451,7 @@ func (ms *MapStorage) SetLoadIDsDrv(loadIDs map[string]int64) (err error) { ms.mu.Unlock() return } + +func (ms *MapStorage) RemoveLoadIDsDrv() (err error) { + return utils.ErrNotImplemented +} diff --git a/engine/storage_mongo_datadb.go b/engine/storage_mongo_datadb.go index 17d8d1396..256df75bc 100644 --- a/engine/storage_mongo_datadb.go +++ b/engine/storage_mongo_datadb.go @@ -2274,3 +2274,10 @@ func (ms *MongoStorage) SetLoadIDsDrv(loadIDs map[string]int64) (err error) { return err }) } + +func (ms *MongoStorage) RemoveLoadIDsDrv() (err error) { + return ms.query(func(sctx mongo.SessionContext) (err error) { + _, err = ms.getCol(ColLID).DeleteMany(sctx, bson.M{}) + return err + }) +} diff --git a/engine/storage_redis.go b/engine/storage_redis.go index ef548797d..62f2b25db 100644 --- a/engine/storage_redis.go +++ b/engine/storage_redis.go @@ -1675,3 +1675,7 @@ func (rs *RedisStorage) GetItemLoadIDsDrv(itemIDPrefix string) (loadIDs map[stri func (rs *RedisStorage) SetLoadIDsDrv(loadIDs map[string]int64) error { return rs.Cmd(redis_HMSET, utils.LoadIDs, loadIDs).Err } + +func (rs *RedisStorage) RemoveLoadIDsDrv() (err error) { + return rs.Cmd(redis_DEL, utils.LoadIDs).Err +} diff --git a/engine/version.go b/engine/version.go index ac21dde90..de175a0ce 100644 --- a/engine/version.go +++ b/engine/version.go @@ -33,6 +33,7 @@ var ( utils.ActionPlans: "cgr-migrator -exec=*action_plans", utils.SharedGroups: "cgr-migrator -exec=*shared_groups", utils.Thresholds: "cgr-migrator -exec=*thresholds", + utils.LoadIDsVrs: "cgr-migrator -exec=*load_ids", } storDBVers = map[string]string{ utils.CostDetails: "cgr-migrator -exec=*cost_details", @@ -155,6 +156,7 @@ func CurrentDataDBVersions() Versions { utils.RatingProfile: 1, utils.Chargers: 1, utils.Dispatchers: 1, + utils.LoadIDsVrs: 1, } } diff --git a/migrator/loadids.go b/migrator/loadids.go new file mode 100644 index 000000000..3df31eb0d --- /dev/null +++ b/migrator/loadids.go @@ -0,0 +1,52 @@ +/* +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 +*/ + +package migrator + +import ( + "fmt" + + "github.com/cgrates/cgrates/engine" + "github.com/cgrates/cgrates/utils" +) + +// +func (m *Migrator) migrateLoadIDs() (err error) { + var vrs engine.Versions + if vrs, err = m.dmIN.DataManager().DataDB().GetVersions(""); err != nil { + return utils.NewCGRError(utils.Migrator, + utils.ServerErrorCaps, + err.Error(), + fmt.Sprintf("error: <%s> when querying oldDataDB for versions", err.Error())) + } + if vrs[utils.LoadIDs] != 1 { + if err = m.dmOut.DataManager().DataDB().RemoveLoadIDsDrv(); err != nil { + return + } + // All done, update version wtih current one + vrs := engine.Versions{utils.LoadIDsVrs: engine.CurrentDataDBVersions()[utils.LoadIDsVrs]} + if err = m.dmOut.DataManager().DataDB().SetVersions(vrs, false); err != nil { + return utils.NewCGRError(utils.Migrator, + utils.ServerErrorCaps, + err.Error(), + fmt.Sprintf("error: <%s> when updating LoadIDs version into dataDB", err)) + } + } + + return +} diff --git a/migrator/migrator.go b/migrator/migrator.go index f994c4c57..3b7610420 100755 --- a/migrator/migrator.go +++ b/migrator/migrator.go @@ -191,6 +191,8 @@ func (m *Migrator) Migrate(taskIDs []string) (err error, stats map[string]int) { err = m.migrateTPChargers() case utils.MetaTpDispatchers: err = m.migrateTPDispatchers() + case utils.MetaLoadIDs: + err = m.migrateLoadIDs() //DATADB ALL case utils.MetaDataDB: if err := m.migrateAccounts(); err != nil { @@ -256,6 +258,9 @@ func (m *Migrator) Migrate(taskIDs []string) (err error, stats map[string]int) { if err := m.migrateDispatchers(); err != nil { log.Print("ERROR: ", utils.MetaDispatchers, " ", err) } + if err = m.migrateLoadIDs(); err != nil { + log.Print("ERROR: ", utils.MetaLoadIDs, " ", err) + } err = nil //STORDB ALL case utils.MetaStorDB: diff --git a/utils/consts.go b/utils/consts.go index ce28b43a5..2fedbe3ef 100755 --- a/utils/consts.go +++ b/utils/consts.go @@ -414,6 +414,7 @@ const ( Chargers = "Chargers" Dispatchers = "Dispatchers" StatS = "Stats" + LoadIDsVrs = "LoadIDs" RALService = "RALs" CostSource = "CostSource" ExtraInfo = "ExtraInfo" @@ -695,6 +696,7 @@ const ( CapThresholdHits = "ThresholdHits" CapThresholds = "Thresholds" CapStatQueues = "StatQueues" + MetaLoadIDs = "*load_ids" ) const (