From c35b2a90bbe166ef4e070365249636713899f20c Mon Sep 17 00:00:00 2001 From: edwardro22 Date: Tue, 14 Nov 2017 13:16:02 +0000 Subject: [PATCH] Added move feature(to migrate data from one db to another) and updated GetTPIds , IsDBempty and the versioning accordingly --- apier/v1/tp.go | 2 +- cmd/cgr-migrator/cgr-migrator.go | 83 +-- data/storage/migrator/usage_float_to_int.sql | 2 +- engine/loader_it_test.go | 2 +- engine/storage_csv.go | 2 +- engine/storage_interface.go | 2 +- engine/storage_mongo_stordb.go | 40 +- engine/storage_sql.go | 99 +++- engine/version.go | 53 +- engine/versions_it_test.go | 34 +- migrator/accounts.go | 62 ++- migrator/action.go | 67 ++- migrator/action_plan.go | 63 ++- migrator/action_trigger.go | 69 ++- migrator/alias.go | 134 +++++ migrator/cdrstats.go | 71 +++ migrator/derived_chargers.go | 78 +++ migrator/destinations.go | 132 +++++ migrator/lcr.go | 78 +++ migrator/migrator.go | 236 ++++++++- migrator/{v1datadb.go => migratorDataDB.go} | 2 +- migrator/migrator_it_test.go | 528 ++++++++++++++++--- migrator/rating_plan.go | 78 +++ migrator/rating_profile.go | 78 +++ migrator/request_filter.go | 78 +++ migrator/resource.go | 80 +++ migrator/sharedgroup.go | 63 ++- migrator/stats.go | 108 +++- migrator/subscribers.go | 71 +++ migrator/thresholds.go | 134 +++-- migrator/timings.go | 78 +++ migrator/tp_account_actions.go | 76 +++ migrator/tp_action_plans.go | 83 +++ migrator/tp_action_triggers.go | 83 +++ migrator/tp_actions.go | 83 +++ migrator/tp_aliases.go | 77 +++ migrator/tp_cdr_stats.go | 83 +++ migrator/tp_derived_chargers.go | 78 +++ migrator/tp_destination_rates.go | 82 +++ migrator/tp_destinations.go | 82 +++ migrator/tp_filters.go | 82 +++ migrator/tp_lcrs.go | 76 +++ migrator/tp_rates.go | 83 +++ migrator/tp_rating_plans.go | 83 +++ migrator/tp_rating_profiles.go | 77 +++ migrator/tp_resources.go | 83 +++ migrator/tp_shared_groups.go | 83 +++ migrator/tp_stats.go | 83 +++ migrator/tp_thresholds.go | 83 +++ migrator/tp_timings.go | 83 +++ migrator/tp_users.go | 77 +++ migrator/user.go | 78 +++ migrator/v1migrator_utils.go | 15 +- migrator/v1mongo_data.go | 2 +- migrator/v1redis.go | 30 +- utils/consts.go | 130 ++++- 56 files changed, 4180 insertions(+), 302 deletions(-) create mode 100644 migrator/alias.go create mode 100644 migrator/cdrstats.go create mode 100644 migrator/derived_chargers.go create mode 100644 migrator/destinations.go create mode 100644 migrator/lcr.go rename migrator/{v1datadb.go => migratorDataDB.go} (97%) create mode 100644 migrator/rating_plan.go create mode 100644 migrator/rating_profile.go create mode 100644 migrator/request_filter.go create mode 100644 migrator/resource.go create mode 100644 migrator/subscribers.go create mode 100644 migrator/timings.go create mode 100644 migrator/tp_account_actions.go create mode 100644 migrator/tp_action_plans.go create mode 100644 migrator/tp_action_triggers.go create mode 100644 migrator/tp_actions.go create mode 100644 migrator/tp_aliases.go create mode 100644 migrator/tp_cdr_stats.go create mode 100644 migrator/tp_derived_chargers.go create mode 100644 migrator/tp_destination_rates.go create mode 100644 migrator/tp_destinations.go create mode 100644 migrator/tp_filters.go create mode 100644 migrator/tp_lcrs.go create mode 100644 migrator/tp_rates.go create mode 100644 migrator/tp_rating_plans.go create mode 100644 migrator/tp_rating_profiles.go create mode 100644 migrator/tp_resources.go create mode 100644 migrator/tp_shared_groups.go create mode 100644 migrator/tp_stats.go create mode 100644 migrator/tp_thresholds.go create mode 100644 migrator/tp_timings.go create mode 100644 migrator/tp_users.go create mode 100644 migrator/user.go diff --git a/apier/v1/tp.go b/apier/v1/tp.go index 42291c5ff..9c9b856a0 100644 --- a/apier/v1/tp.go +++ b/apier/v1/tp.go @@ -35,7 +35,7 @@ type AttrGetTPIds struct { // Queries tarrif plan identities gathered from all tables. func (self *ApierV1) GetTPIds(attrs AttrGetTPIds, reply *[]string) error { - if ids, err := self.StorDb.GetTpIds(); err != nil { + if ids, err := self.StorDb.GetTpIds(""); err != nil { return utils.NewErrServerError(err) } else if ids == nil { return utils.ErrNotFound diff --git a/cmd/cgr-migrator/cgr-migrator.go b/cmd/cgr-migrator/cgr-migrator.go index ba7b1ef45..2b7b8d205 100755 --- a/cmd/cgr-migrator/cgr-migrator.go +++ b/cmd/cgr-migrator/cgr-migrator.go @@ -31,36 +31,37 @@ import ( ) var ( - oldDataDB migrator.V1DataDB + sameDBname true + inDataDB migrator.MigratorDataDB oldstorDB engine.Storage oStorDBType string - odataDBType string + oDataDBType string oDBDataEncoding string migrate = flag.String("migrate", "", "Fire up automatic migration *to use multiple values use ',' as separator \n <*set_versions|*cost_details|*accounts|*actions|*action_triggers|*action_plans|*shared_groups> ") version = flag.Bool("version", false, "Prints the application version.") - dataDBType = flag.String("datadb_type", config.CgrConfig().DataDbType, "The type of the DataDb database ") - dataDBHost = flag.String("datadb_host", config.CgrConfig().DataDbHost, "The DataDb host to connect to.") - dataDBPort = flag.String("datadb_port", config.CgrConfig().DataDbPort, "The DataDb port to bind to.") - dataDBName = flag.String("datadb_name", config.CgrConfig().DataDbName, "The name/number of the DataDb to connect to.") - dataDBUser = flag.String("datadb_user", config.CgrConfig().DataDbUser, "The DataDb user to sign in as.") - dataDBPass = flag.String("datadb_passwd", config.CgrConfig().DataDbPass, "The DataDb user's password.") + outDataDBType = flag.String("out_datadb_type", config.CgrConfig().DataDbType, "The type of the DataDb Database ") + outDataDBHost = flag.String("out_datadb_host", config.CgrConfig().DataDbHost, "The DataDb host to connect to.") + outDataDBPort = flag.String("out_datadb_port", config.CgrConfig().DataDbPort, "The DataDb port to bind to.") + outDataDBName = flag.String("out_datadb_name", config.CgrConfig().DataDbName, "The name/number of the DataDb to connect to.") + outDataDBUser = flag.String("out_datadb_user", config.CgrConfig().DataDbUser, "The DataDb user to sign in as.") + outDataDBPass = flag.String("out_datadb_passwd", config.CgrConfig().DataDbPass, "The DataDb user's password.") - storDBType = flag.String("stordb_type", config.CgrConfig().StorDBType, "The type of the storDb database ") + storDBType = flag.String("stordb_type", config.CgrConfig().StorDBType, "The type of the storDb Database ") storDBHost = flag.String("stordb_host", config.CgrConfig().StorDBHost, "The storDb host to connect to.") storDBPort = flag.String("stordb_port", config.CgrConfig().StorDBPort, "The storDb port to bind to.") storDBName = flag.String("stordb_name", config.CgrConfig().StorDBName, "The name/number of the storDb to connect to.") storDBUser = flag.String("stordb_user", config.CgrConfig().StorDBUser, "The storDb user to sign in as.") storDBPass = flag.String("stordb_passwd", config.CgrConfig().StorDBPass, "The storDb user's password.") - oldDataDBType = flag.String("old_datadb_type", "", "The type of the DataDb database ") - oldDataDBHost = flag.String("old_datadb_host", config.CgrConfig().DataDbHost, "The DataDb host to connect to.") - oldDataDBPort = flag.String("old_datadb_port", config.CgrConfig().DataDbPort, "The DataDb port to bind to.") - oldDataDBName = flag.String("old_datadb_name", config.CgrConfig().DataDbName, "The name/number of the DataDb to connect to.") - oldDataDBUser = flag.String("old_datadb_user", config.CgrConfig().DataDbUser, "The DataDb user to sign in as.") - oldDataDBPass = flag.String("old_datadb_passwd", config.CgrConfig().DataDbPass, "The DataDb user's password.") + inDataDBType = flag.String("in_datadb_type", "", "The type of the DataDb Database ") + inDataDBHost = flag.String("in_datadb_host", config.CgrConfig().DataDbHost, "The DataDb host to connect to.") + inDataDBPort = flag.String("in_datadb_port", config.CgrConfig().DataDbPort, "The DataDb port to bind to.") + inDataDBName = flag.String("in_datadb_name", config.CgrConfig().DataDbName, "The name/number of the DataDb to connect to.") + inDataDBUser = flag.String("in_datadb_user", config.CgrConfig().DataDbUser, "The DataDb user to sign in as.") + inDataDBPass = flag.String("in_datadb_passwd", config.CgrConfig().DataDbPass, "The DataDb user's password.") - oldStorDBType = flag.String("old_stordb_type", "", "The type of the storDb database ") + oldStorDBType = flag.String("old_stordb_type", "", "The type of the storDb Database ") oldStorDBHost = flag.String("old_stordb_host", config.CgrConfig().StorDBHost, "The storDb host to connect to.") oldStorDBPort = flag.String("old_stordb_port", config.CgrConfig().StorDBPort, "The storDb port to bind to.") oldStorDBName = flag.String("old_stordb_name", config.CgrConfig().StorDBName, "The name/number of the storDb to connect to.") @@ -70,11 +71,11 @@ var ( loadHistorySize = flag.Int("load_history_size", config.CgrConfig().LoadHistorySize, "Limit the number of records in the load history") oldLoadHistorySize = flag.Int("old_load_history_size", 0, "Limit the number of records in the load history") - dbDataEncoding = flag.String("dbdata_encoding", config.CgrConfig().DBDataEncoding, "The encoding used to store object data in strings") - oldDBDataEncoding = flag.String("old_dbdata_encoding", "", "The encoding used to store object data in strings") - dryRun = flag.Bool("dry_run", false, "When true will not save loaded data to dataDb but just parse it for consistency and errors.") - verbose = flag.Bool("verbose", false, "Enable detailed verbose logging output") - stats = flag.Bool("stats", false, "Generates statsistics about migrated data.") + dbDataEncoding = flag.String("dbData_encoding", config.CgrConfig().DBDataEncoding, "The encoding used to store object Data in strings") + inDBDataEncoding = flag.String("in_dbData_encoding", "", "The encoding used to store object Data in strings") + dryRun = flag.Bool("dry_run", false, "When true will not save loaded Data to DataDb but just parse it for consistency and errors.") + verbose = flag.Bool("verbose", false, "Enable detailed verbose logging output") + stats = flag.Bool("stats", false, "Generates statsistics about migrated Data.") ) func main() { @@ -85,31 +86,30 @@ func main() { } if migrate != nil && *migrate != "" { // Run migrator if *verbose { - log.Print("Initializing dataDB:", *dataDBType) + log.Print("Initializing DataDB:", *outDataDBType) log.Print("Initializing storDB:", *storDBType) } - var dm *engine.DataManager - dm, _ = engine.ConfigureDataStorage(*dataDBType, *dataDBHost, *dataDBPort, *dataDBName, - *dataDBUser, *dataDBPass, *dbDataEncoding, config.CgrConfig().CacheCfg(), *loadHistorySize) - storDB, err := engine.ConfigureStorStorage(*storDBType, *storDBHost, *storDBPort, - *storDBName, *storDBUser, *storDBPass, *dbDataEncoding, - config.CgrConfig().StorDBMaxOpenConns, config.CgrConfig().StorDBMaxIdleConns, - config.CgrConfig().StorDBConnMaxLifetime, config.CgrConfig().StorDBCDRSIndexes) + var dmOUT *engine.DataManager + dmOUT, _ = engine.ConfigureDataStorage(*outDataDBType, *outDataDBHost, *outDataDBPort, *outDataDBName, *outDataDBUser, *outDataDBPass, *dbDataEncoding, config.CgrConfig().CacheConfig, *loadHistorySize) + storDB, err := engine.ConfigureStorStorage(*storDBType, *storDBHost, *storDBPort, *storDBName, *storDBUser, *storDBPass, *dbDataEncoding, + config.CgrConfig().StorDBMaxOpenConns, config.CgrConfig().StorDBMaxIdleConns, config.CgrConfig().StorDBConnMaxLifetime, config.CgrConfig().StorDBCDRSIndexes) if err != nil { log.Fatal(err) } - if *oldDataDBType == "" { - *oldDataDBType = *dataDBType - *oldDataDBHost = *dataDBHost - *oldDataDBPort = *dataDBPort - *oldDataDBName = *dataDBName - *oldDataDBUser = *dataDBUser - *oldDataDBPass = *dataDBPass + if *inDataDBType == "" { + *inDataDBType = *outDataDBType + *inDataDBHost = *outDataDBHost + *inDataDBPort = *outDataDBPort + *inDataDBName = *outDataDBName + *inDataDBUser = *outDataDBUser + *inDataDBPass = *outDataDBPass } if *verbose { - log.Print("Initializing oldDataDB:", *oldDataDBType) + log.Print("Initializing inDataDB:", *inDataDBType) } - oldDataDB, err := migrator.ConfigureV1DataStorage(*oldDataDBType, *oldDataDBHost, *dataDBPort, *dataDBName, *dataDBUser, *dataDBPass, *dbDataEncoding) + var dmIN *engine.DataManager + dmIN, _ = engine.ConfigureDataStorage(*inDataDBType, *inDataDBHost, *inDataDBPort, *inDataDBName, *inDataDBUser, *inDataDBPass, *dbDataEncoding, config.CgrConfig().CacheConfig, *loadHistorySize) + inDataDB, err := migrator.ConfigureV1DataStorage(*inDataDBType, *inDataDBHost, *inDataDBPort, *inDataDBName, *inDataDBUser, *inDataDBPass, *dbDataEncoding) if err != nil { log.Fatal(err) } @@ -123,7 +123,7 @@ func main() { } } if *oldStorDBType != "" { - oldstorDB, err = engine.ConfigureStorStorage(oStorDBType, *oldStorDBHost, *oldStorDBPort, *oldStorDBName, *oldStorDBUser, *oldStorDBPass, *oldDBDataEncoding, + oldstorDB, err = engine.ConfigureStorStorage(oStorDBType, *oldStorDBHost, *oldStorDBPort, *oldStorDBName, *oldStorDBUser, *oldStorDBPass, *inDBDataEncoding, config.CgrConfig().StorDBMaxOpenConns, config.CgrConfig().StorDBMaxIdleConns, config.CgrConfig().StorDBConnMaxLifetime, config.CgrConfig().StorDBCDRSIndexes) if err != nil { log.Fatal(err) @@ -132,7 +132,10 @@ func main() { if *verbose { log.Print("Migrating: ", *migrate) } - m, err := migrator.NewMigrator(dm, *dataDBType, *dbDataEncoding, storDB, *storDBType, oldDataDB, *oldDataDBType, *oldDBDataEncoding, oldstorDB, *oldStorDBType, *dryRun) + if inDataDBName != outDataDBName { + sameDBname := false + } + m, err := migrator.NewMigrator(dmIN, dmOUT, *outDataDBType, *dbDataEncoding, storDB, *storDBType, inDataDB, *inDataDBType, *inDBDataEncoding, oldstorDB, *oldStorDBType, *dryRun, sameDBname) if err != nil { log.Fatal(err) } diff --git a/data/storage/migrator/usage_float_to_int.sql b/data/storage/migrator/usage_float_to_int.sql index 9061b2ceb..1e4df20cc 100644 --- a/data/storage/migrator/usage_float_to_int.sql +++ b/data/storage/migrator/usage_float_to_int.sql @@ -1,4 +1,4 @@ -ALTER TABLE cdrs CHANGE COLUMN `usage` `usage_old` DECIMAL(30,9); +ALTER TABLE cdrs CHANGE COLUMN `usage` `usage_old` DECIMAL(30); ALTER TABLE cdrs ADD `usage` BIGINT; UPDATE cdrs SET `usage` = `usage_old` * 1000000000 WHERE usage_old IS NOT NULL; ALTER TABLE cdrs DROP COLUMN usage_old; \ No newline at end of file diff --git a/engine/loader_it_test.go b/engine/loader_it_test.go index 2ca9e484f..ad6c89f55 100755 --- a/engine/loader_it_test.go +++ b/engine/loader_it_test.go @@ -367,7 +367,7 @@ func TestLoaderITImportToStorDb(t *testing.T) { if err := csvImporter.Run(); err != nil { t.Error("Error when importing tpdata to storDb: ", err) } - if tpids, err := storDb.GetTpIds(); err != nil { + if tpids, err := storDb.GetTpIds(""); err != nil { t.Error("Error when querying storDb for imported data: ", err) } else if len(tpids) != 1 || tpids[0] != utils.TEST_SQL { t.Errorf("Data in storDb is different than expected %v", tpids) diff --git a/engine/storage_csv.go b/engine/storage_csv.go index f7b55867e..8359a36b5 100755 --- a/engine/storage_csv.go +++ b/engine/storage_csv.go @@ -705,7 +705,7 @@ func (csvs *CSVStorage) GetTPFilters(tpid, id string) ([]*utils.TPFilter, error) return tpFilter.AsTPFilter(), nil } -func (csvs *CSVStorage) GetTpIds() ([]string, error) { +func (csvs *CSVStorage) GetTpIds(x string) ([]string, error) { return nil, utils.ErrNotImplemented } diff --git a/engine/storage_interface.go b/engine/storage_interface.go index 40c389626..d8b2e6297 100755 --- a/engine/storage_interface.go +++ b/engine/storage_interface.go @@ -153,7 +153,7 @@ type LoadStorage interface { // LoadReader reads from .csv or TP tables and provides the data ready for the tp_db or data_db. type LoadReader interface { - GetTpIds() ([]string, error) + GetTpIds(string) ([]string, error) GetTpTableIds(string, string, utils.TPDistinctIds, map[string]string, *utils.Paginator) ([]string, error) GetTPTimings(string, string) ([]*utils.ApierTPTiming, error) GetTPDestinations(string, string) ([]*utils.TPDestination, error) diff --git a/engine/storage_mongo_stordb.go b/engine/storage_mongo_stordb.go index f21ede633..796e68e78 100755 --- a/engine/storage_mongo_stordb.go +++ b/engine/storage_mongo_stordb.go @@ -28,31 +28,47 @@ import ( "time" ) -func (ms *MongoStorage) GetTpIds() ([]string, error) { +func (ms *MongoStorage) GetTpIds(x string) ([]string, error) { tpidMap := make(map[string]bool) session := ms.session.Copy() db := session.DB(ms.db) defer session.Close() - cols, err := db.CollectionNames() - if err != nil { - return nil, err - } - for _, col := range cols { - if strings.HasPrefix(col, "tp_") { + var tpids []string + if x != "" { + if strings.HasPrefix(x, "tp_") { tpids := make([]string, 0) - if err := db.C(col).Find(nil).Select(bson.M{"tpid": 1}).Distinct("tpid", &tpids); err != nil { + if err := db.C(x).Find(nil).Select(bson.M{"tpid": 1}).Distinct("tpid", &tpids); err != nil { return nil, err } for _, tpid := range tpids { tpidMap[tpid] = true } } - } - var tpids []string - for tpid := range tpidMap { - tpids = append(tpids, tpid) + for tpid := range tpidMap { + tpids = append(tpids, tpid) + } + } else { + cols, err := db.CollectionNames() + if err != nil { + return nil, err + } + for _, col := range cols { + if strings.HasPrefix(col, "tp_") { + tpids := make([]string, 0) + if err := db.C(col).Find(nil).Select(bson.M{"tpid": 1}).Distinct("tpid", &tpids); err != nil { + return nil, err + } + for _, tpid := range tpids { + tpidMap[tpid] = true + } + } + } + for tpid := range tpidMap { + tpids = append(tpids, tpid) + } } return tpids, nil + } func (ms *MongoStorage) GetTpTableIds(tpid, table string, distinct utils.TPDistinctIds, filter map[string]string, pag *utils.Paginator) ([]string, error) { diff --git a/engine/storage_sql.go b/engine/storage_sql.go index a5280a259..351400690 100755 --- a/engine/storage_sql.go +++ b/engine/storage_sql.go @@ -101,11 +101,14 @@ func (self *SQLStorage) CreateTablesFromScript(scriptPath string) error { } func (self *SQLStorage) IsDBEmpty() (resp bool, err error) { - tbls := []string{utils.TBLTPTimings, utils.TBLTPDestinations, utils.TBLTPRates, + tbls := []string{ + utils.TBLTPTimings, utils.TBLTPDestinations, utils.TBLTPRates, utils.TBLTPDestinationRates, utils.TBLTPRatingPlans, utils.TBLTPRateProfiles, utils.TBLTPSharedGroups, utils.TBLTPCdrStats, utils.TBLTPLcrs, utils.TBLTPActions, - utils.TBLTPActionPlans, utils.TBLTPActionTriggers, utils.TBLTPAccountActions, - utils.TBLTPDerivedChargers, utils.TBLTPAliases, utils.TBLTPUsers, utils.TBLTPResources, utils.TBLTPStats} + utils.TBLTPActionTriggers, utils.TBLTPAccountActions, utils.TBLTPDerivedChargers, utils.TBLTPUsers, + utils.TBLTPAliases, utils.TBLTPResources, utils.TBLTPStats, utils.TBLTPThresholds, + utils.TBLTPFilters, utils.TBLSMCosts, utils.TBLCDRs, utils.TBLTPActionPlans, utils.TBLVersions, + } for _, tbl := range tbls { if self.db.HasTable(tbl) { return false, nil @@ -115,35 +118,76 @@ func (self *SQLStorage) IsDBEmpty() (resp bool, err error) { return true, nil } +// update // Return a list with all TPids defined in the system, even if incomplete, isolated in some table. -func (self *SQLStorage) GetTpIds() ([]string, error) { - rows, err := self.Db.Query( - fmt.Sprintf("(SELECT tpid FROM %s) UNION (SELECT tpid FROM %s) UNION (SELECT tpid FROM %s) UNION (SELECT tpid FROM %s) UNION (SELECT tpid FROM %s) UNION (SELECT tpid FROM %s)", - utils.TBLTPTimings, - utils.TBLTPDestinations, - utils.TBLTPRates, - utils.TBLTPDestinationRates, - utils.TBLTPRatingPlans, - utils.TBLTPRateProfiles)) - if err != nil { - return nil, err - } - defer rows.Close() - ids := make([]string, 0) - i := 0 - for rows.Next() { - i++ //Keep here a reference so we know we got at least one - var id string - err = rows.Scan(&id) +func (self *SQLStorage) GetTpIds(x string) ([]string, error) { + if x != "" { + rows, err := self.Db.Query( + fmt.Sprintf(" (SELECT tpid FROM %s)", x)) if err != nil { return nil, err } - ids = append(ids, id) + defer rows.Close() + ids := make([]string, 0) + i := 0 + for rows.Next() { + i++ //Keep here a reference so we know we got at least one + var id string + err = rows.Scan(&id) + if err != nil { + return nil, err + } + ids = append(ids, id) + } + if i == 0 { + return nil, nil + } + return ids, nil + } else { + rows, err := self.Db.Query( + fmt.Sprintf( + "(SELECT tpid FROM %s) UNION (SELECT tpid FROM %s) UNION (SELECT tpid FROM %s) UNION (SELECT tpid FROM %s) UNION (SELECT tpid FROM %s) UNION (SELECT tpid FROM %s) UNION (SELECT tpid FROM %s) UNION (SELECT tpid FROM %s) UNION (SELECT tpid FROM %s) UNION (SELECT tpid FROM %s) UNION (SELECT tpid FROM %s) UNION (SELECT tpid FROM %s) UNION (SELECT tpid FROM %s) UNION (SELECT tpid FROM %s) UNION (SELECT tpid FROM %s) UNION (SELECT tpid FROM %s) UNION (SELECT tpid FROM %s) UNION (SELECT tpid FROM %s) UNION (SELECT tpid FROM %s) UNION (SELECT tpid FROM %s)", + utils.TBLTPTimings, + utils.TBLTPDestinations, + utils.TBLTPRates, + utils.TBLTPDestinationRates, + utils.TBLTPRatingPlans, + utils.TBLTPRateProfiles, + utils.TBLTPSharedGroups, + utils.TBLTPCdrStats, + utils.TBLTPLcrs, + utils.TBLTPActions, + utils.TBLTPActionTriggers, + utils.TBLTPAccountActions, + utils.TBLTPDerivedChargers, + utils.TBLTPUsers, + utils.TBLTPAliases, + utils.TBLTPResources, + utils.TBLTPStats, + utils.TBLTPThresholds, + utils.TBLTPFilters, + utils.TBLTPActionPlans)) + if err != nil { + return nil, err + } + defer rows.Close() + ids := make([]string, 0) + i := 0 + for rows.Next() { + i++ //Keep here a reference so we know we got at least one + var id string + err = rows.Scan(&id) + if err != nil { + return nil, err + } + ids = append(ids, id) + } + if i == 0 { + return nil, nil + } + + return ids, nil } - if i == 0 { - return nil, nil - } - return ids, nil } // ToDo: TEST @@ -206,6 +250,7 @@ func (self *SQLStorage) GetTpTableIds(tpid, table string, distinct utils.TPDisti func (self *SQLStorage) RemTpData(table, tpid string, args map[string]string) error { tx := self.db.Begin() + if len(table) == 0 { // Remove tpid out of all tables for _, tblName := range []string{utils.TBLTPTimings, utils.TBLTPDestinations, utils.TBLTPRates, utils.TBLTPDestinationRates, utils.TBLTPRatingPlans, utils.TBLTPRateProfiles, utils.TBLTPSharedGroups, utils.TBLTPCdrStats, utils.TBLTPLcrs, utils.TBLTPActions, utils.TBLTPActionPlans, utils.TBLTPActionTriggers, utils.TBLTPAccountActions, diff --git a/engine/version.go b/engine/version.go index ec7d7ffb8..b17a29228 100644 --- a/engine/version.go +++ b/engine/version.go @@ -128,11 +128,60 @@ func CurrentDBVersions(storType string) Versions { } func CurrentDataDBVersions() Versions { - return Versions{utils.StatS: 2, utils.Accounts: 2, utils.Actions: 2, utils.ActionTriggers: 2, utils.ActionPlans: 2, utils.SharedGroups: 2, utils.Thresholds: 2} + return Versions{ + utils.StatS: 2, + utils.Accounts: 2, + utils.Actions: 2, + utils.ActionTriggers: 2, + utils.ActionPlans: 2, + utils.SharedGroups: 2, + utils.Thresholds: 2, + utils.Timing: 2, + utils.RQF: 2, + utils.Resource: 2, + utils.ReverseAlias: 2, + utils.Alias: 2, + utils.User: 2, + utils.Subscribers: 2, + utils.DerivedChargersV: 2, + utils.CdrStats: 2, + utils.Destinations: 2, + utils.ReverseDestinations: 2, + utils.LCR: 2, + utils.RatingPlan: 2, + utils.RatingProfile: 2, + } } func CurrentStorDBVersions() Versions { - return Versions{utils.COST_DETAILS: 2} + return Versions{ + utils.COST_DETAILS: 2, + utils.TpRatingPlans: 2, + utils.TpLcrs: 2, + utils.TpFilters: 2, + utils.TpDestinationRates: 2, + utils.TpActionTriggers: 2, + utils.TpAccountActions: 2, + utils.TpActionPlans: 2, + utils.TpActions: 2, + utils.TpDerivedCharges: 2, + utils.TpThresholds: 2, + utils.TpStats: 2, + utils.TpSharedGroups: 2, + utils.TpRatingProfiles: 2, + utils.TpResources: 2, + utils.TpRates: 2, + utils.TpTiming: 2, + utils.TpResource: 2, + utils.TpAliases: 2, + utils.TpUsers: 2, + utils.TpDerivedChargersV: 2, + utils.TpCdrStats: 2, + utils.TpDestinations: 2, + utils.TpLCR: 2, + utils.TpRatingPlan: 2, + utils.TpRatingProfile: 2, + } } // Versions will keep trac of various item versions diff --git a/engine/versions_it_test.go b/engine/versions_it_test.go index 9b38aff9f..6dd14e163 100644 --- a/engine/versions_it_test.go +++ b/engine/versions_it_test.go @@ -126,16 +126,29 @@ func testVersion(t *testing.T) { var test string var currentVersion Versions var testVersion Versions + dataDbVersions := CurrentDataDBVersions() + storDbVersions := CurrentStorDBVersions() + + allVersions := make(Versions) + for k, v := range dataDbVersions { + allVersions[k] = v + } + for k, v := range storDbVersions { + allVersions[k] = v + } + storType := dm3.DataDB().GetStorageType() switch storType { case utils.MONGO, utils.MAPSTOR: - currentVersion = Versions{utils.Accounts: 2, utils.Actions: 2, - utils.ActionTriggers: 2, utils.ActionPlans: 2, utils.SharedGroups: 2, utils.COST_DETAILS: 2, utils.CDRs: 2} - testVersion = Versions{utils.Accounts: 1, utils.Actions: 2, utils.ActionTriggers: 2, utils.ActionPlans: 2, utils.SharedGroups: 2, utils.COST_DETAILS: 2} + currentVersion = allVersions + testVersion = allVersions + testVersion[utils.Accounts] = 1 test = "Migration needed: please backup cgr data and run : " case utils.REDIS: - currentVersion = CurrentDataDBVersions() - testVersion = Versions{utils.Accounts: 1, utils.Actions: 2, utils.ActionTriggers: 2, utils.ActionPlans: 2, utils.SharedGroups: 2} + currentVersion = dataDbVersions + testVersion = dataDbVersions + testVersion[utils.Accounts] = 1 + test = "Migration needed: please backup cgr data and run : " } @@ -169,14 +182,21 @@ func testVersion(t *testing.T) { storType = storageDb.GetStorageType() switch storType { case utils.MONGO, utils.MAPSTOR: +<<<<<<< HEAD currentVersion = Versions{utils.Accounts: 2, utils.Actions: 2, utils.ActionTriggers: 2, utils.ActionPlans: 2, utils.SharedGroups: 2, utils.COST_DETAILS: 2, utils.CDRs: 2} testVersion = Versions{utils.Accounts: 1, utils.Actions: 2, utils.ActionTriggers: 2, utils.ActionPlans: 2, utils.SharedGroups: 2, utils.COST_DETAILS: 2, utils.CDRs: 2} +======= + currentVersion = allVersions + testVersion = allVersions + testVersion[utils.Accounts] = 1 +>>>>>>> Added move feature(to migrate data from one db to another) and updated GetTPIds , IsDBempty and the versioning accordingly test = "Migration needed: please backup cgr data and run : " case utils.POSTGRES, utils.MYSQL: - currentVersion = CurrentStorDBVersions() - testVersion = Versions{utils.COST_DETAILS: 1} + currentVersion = storDbVersions + testVersion = allVersions + testVersion[utils.COST_DETAILS] = 1 test = "Migration needed: please backup cgr data and run : " } //storageDb diff --git a/migrator/accounts.go b/migrator/accounts.go index 5b19419f5..591bb04c7 100755 --- a/migrator/accounts.go +++ b/migrator/accounts.go @@ -33,7 +33,30 @@ const ( v1AccountTBL = "userbalances" ) -func (m *Migrator) migrateAccounts() (err error) { +func (m *Migrator) migrateCurrentAccounts() (err error) { + var ids []string + ids, err = m.dmIN.DataDB().GetKeysForPrefix(utils.ACCOUNT_PREFIX) + if err != nil { + return err + } + for _, id := range ids { + idg := strings.TrimPrefix(id, utils.ACCOUNT_PREFIX) + acc, err := m.dmIN.DataDB().GetAccount(idg) + if err != nil { + return err + } + if acc != nil { + if m.dryRun != true { + if err := m.dmOut.DataDB().SetAccount(acc); err != nil { + return err + } + } + } + } + return +} + +func (m *Migrator) migrateV1Accounts() (err error) { var v1Acnt *v1Account for { v1Acnt, err = m.oldDataDB.getv1Account() @@ -46,7 +69,7 @@ func (m *Migrator) migrateAccounts() (err error) { if v1Acnt != nil { acnt := v1Acnt.AsAccount() if m.dryRun != true { - if err = m.dm.DataDB().SetAccount(acnt); err != nil { + if err = m.dmOut.DataDB().SetAccount(acnt); err != nil { return err } m.stats[utils.Accounts] += 1 @@ -57,7 +80,7 @@ func (m *Migrator) migrateAccounts() (err error) { if m.dryRun != true { // All done, update version wtih current one vrs := engine.Versions{utils.Accounts: engine.CurrentStorDBVersions()[utils.Accounts]} - if err = m.dm.DataDB().SetVersions(vrs, false); err != nil { + if err = m.dmOut.DataDB().SetVersions(vrs, false); err != nil { return utils.NewCGRError(utils.Migrator, utils.ServerErrorCaps, err.Error(), @@ -67,6 +90,39 @@ func (m *Migrator) migrateAccounts() (err error) { return } +func (m *Migrator) migrateAccounts() (err error) { + var vrs engine.Versions + current := engine.CurrentDataDBVersions() + vrs, err = m.dmOut.DataDB().GetVersions(utils.TBLVersions) + if err != nil { + return utils.NewCGRError(utils.Migrator, + utils.ServerErrorCaps, + err.Error(), + fmt.Sprintf("error: <%s> when querying oldDataDB for versions", err.Error())) + } else if len(vrs) == 0 { + return utils.NewCGRError(utils.Migrator, + utils.MandatoryIEMissingCaps, + utils.UndefinedVersion, + "version number is not defined for ActionTriggers model") + } + switch vrs[utils.Accounts] { + case current[utils.Accounts]: + if m.sameDBname { + return + } + if err := m.migrateCurrentAccounts(); err != nil { + return err + } + return + + case 1: + if err := m.migrateV1Accounts(); err != nil { + return err + } + } + return +} + type v1Account struct { Id string BalanceMap map[string]v1BalanceChain diff --git a/migrator/action.go b/migrator/action.go index 6fce8b768..0c809ba36 100644 --- a/migrator/action.go +++ b/migrator/action.go @@ -20,6 +20,7 @@ package migrator import ( "fmt" + "strings" "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/utils" @@ -38,7 +39,30 @@ type v1Action struct { type v1Actions []*v1Action -func (m *Migrator) migrateActions() (err error) { +func (m *Migrator) migrateCurrentActions() (err error) { + var ids []string + ids, err = m.dmIN.DataDB().GetKeysForPrefix(utils.ACTION_PREFIX) + if err != nil { + return err + } + for _, id := range ids { + idg := strings.TrimPrefix(id, utils.ACTION_PREFIX) + acts, err := m.dmIN.GetActions(idg, true, utils.NonTransactional) + if err != nil { + return err + } + if acts != nil { + if m.dryRun != true { + if err := m.dmOut.SetActions(idg, acts, utils.NonTransactional); err != nil { + return err + } + } + } + } + return +} + +func (m *Migrator) migrateV1Actions() (err error) { var v1ACs *v1Actions var acts engine.Actions for { @@ -55,18 +79,18 @@ func (m *Migrator) migrateActions() (err error) { acts = append(acts, act) } - if m.dryRun != true { - if err := m.dm.SetActions(acts[0].Id, acts, utils.NonTransactional); err != nil { + if !m.dryRun { + if err := m.dmOut.SetActions(acts[0].Id, acts, utils.NonTransactional); err != nil { return err } m.stats[utils.Actions] += 1 } } } - if m.dryRun != true { + if !m.dryRun { // All done, update version wtih current one vrs := engine.Versions{utils.Actions: engine.CurrentStorDBVersions()[utils.Actions]} - if err = m.dm.DataDB().SetVersions(vrs, false); err != nil { + if err = m.dmOut.DataDB().SetVersions(vrs, false); err != nil { return utils.NewCGRError(utils.Migrator, utils.ServerErrorCaps, err.Error(), @@ -76,6 +100,39 @@ func (m *Migrator) migrateActions() (err error) { return } +func (m *Migrator) migrateActions() (err error) { + var vrs engine.Versions + current := engine.CurrentDataDBVersions() + vrs, err = m.dmOut.DataDB().GetVersions(utils.TBLVersions) + if err != nil { + return utils.NewCGRError(utils.Migrator, + utils.ServerErrorCaps, + err.Error(), + fmt.Sprintf("error: <%s> when querying oldDataDB for versions", err.Error())) + } else if len(vrs) == 0 { + return utils.NewCGRError(utils.Migrator, + utils.MandatoryIEMissingCaps, + utils.UndefinedVersion, + "version number is not defined for ActionTriggers model") + } + switch vrs[utils.Actions] { + case current[utils.Actions]: + if m.sameDBname { + return + } + if err := m.migrateCurrentActions(); err != nil { + return err + } + return + + case 1: + if err := m.migrateV1Actions(); err != nil { + return err + } + } + return +} + func (v1Act v1Action) AsAction() (act *engine.Action) { act = &engine.Action{ Id: v1Act.Id, diff --git a/migrator/action_plan.go b/migrator/action_plan.go index 61461af43..7bd06a7aa 100644 --- a/migrator/action_plan.go +++ b/migrator/action_plan.go @@ -47,7 +47,31 @@ func (at *v1ActionPlan) IsASAP() bool { return at.Timing.Timing.StartTime == utils.ASAP } -func (m *Migrator) migrateActionPlans() (err error) { +func (m *Migrator) migrateCurrentActionPlans() (err error) { + var ids []string + ids, err = m.dmIN.DataDB().GetKeysForPrefix(utils.ACTION_PLAN_PREFIX) + if err != nil { + return err + } + for _, id := range ids { + idg := strings.TrimPrefix(id, utils.ACTION_PLAN_PREFIX) + acts, err := m.dmIN.DataDB().GetActionPlan(idg, true, utils.NonTransactional) + if err != nil { + return err + } + if acts != nil { + if m.dryRun != true { + + if err := m.dmOut.DataDB().SetActionPlan(idg, acts, true, utils.NonTransactional); err != nil { + return err + } + } + } + } + return +} + +func (m *Migrator) migrateV1ActionPlans() (err error) { var v1APs *v1ActionPlans for { v1APs, err = m.oldDataDB.getV1ActionPlans() @@ -61,7 +85,7 @@ func (m *Migrator) migrateActionPlans() (err error) { for _, v1ap := range *v1APs { ap := v1ap.AsActionPlan() if m.dryRun != true { - if err = m.dm.DataDB().SetActionPlan(ap.Id, ap, true, utils.NonTransactional); err != nil { + if err = m.dmOut.DataDB().SetActionPlan(ap.Id, ap, true, utils.NonTransactional); err != nil { return err } m.stats[utils.ActionPlans] += 1 @@ -72,7 +96,7 @@ func (m *Migrator) migrateActionPlans() (err error) { if m.dryRun != true { // All done, update version wtih current one vrs := engine.Versions{utils.ActionPlans: engine.CurrentDataDBVersions()[utils.ActionPlans]} - if err = m.dm.DataDB().SetVersions(vrs, false); err != nil { + if err = m.dmOut.DataDB().SetVersions(vrs, false); err != nil { return utils.NewCGRError(utils.Migrator, utils.ServerErrorCaps, err.Error(), @@ -82,6 +106,39 @@ func (m *Migrator) migrateActionPlans() (err error) { return } +func (m *Migrator) migrateActionPlans() (err error) { + var vrs engine.Versions + current := engine.CurrentDataDBVersions() + vrs, err = m.dmOut.DataDB().GetVersions(utils.TBLVersions) + if err != nil { + return utils.NewCGRError(utils.Migrator, + utils.ServerErrorCaps, + err.Error(), + fmt.Sprintf("error: <%s> when querying oldDataDB for versions", err.Error())) + } else if len(vrs) == 0 { + return utils.NewCGRError(utils.Migrator, + utils.MandatoryIEMissingCaps, + utils.UndefinedVersion, + "version number is not defined for ActionTriggers model") + } + switch vrs[utils.ActionPlans] { + case current[utils.ActionPlans]: + if m.sameDBname { + return + } + if err := m.migrateCurrentActionPlans(); err != nil { + return err + } + return + + case 1: + if err := m.migrateV1ActionPlans(); err != nil { + return err + } + } + return +} + func (v1AP v1ActionPlan) AsActionPlan() (ap *engine.ActionPlan) { for idx, actionId := range v1AP.AccountIds { idElements := strings.Split(actionId, "_") diff --git a/migrator/action_trigger.go b/migrator/action_trigger.go index 852cc0b71..c98c1247b 100644 --- a/migrator/action_trigger.go +++ b/migrator/action_trigger.go @@ -52,7 +52,30 @@ type v1ActionTrigger struct { type v1ActionTriggers []*v1ActionTrigger -func (m *Migrator) migrateActionTriggers() (err error) { +func (m *Migrator) migrateCurrentActionTrigger() (err error) { + var ids []string + ids, err = m.dmIN.DataDB().GetKeysForPrefix(utils.ACTION_TRIGGER_PREFIX) + if err != nil { + return err + } + for _, id := range ids { + idg := strings.TrimPrefix(id, utils.ACTION_TRIGGER_PREFIX) + acts, err := m.dmIN.GetActionTriggers(idg, true, utils.NonTransactional) + if err != nil { + return err + } + if acts != nil { + if m.dryRun != true { + if err := m.dmOut.SetActionTriggers(idg, acts, utils.NonTransactional); err != nil { + return err + } + } + } + } + return +} + +func (m *Migrator) migrateV1ActionTrigger() (err error) { var v1ACTs *v1ActionTriggers var acts engine.ActionTriggers for { @@ -69,18 +92,18 @@ func (m *Migrator) migrateActionTriggers() (err error) { acts = append(acts, act) } - if m.dryRun != true { - if err := m.dm.SetActionTriggers(acts[0].ID, acts, utils.NonTransactional); err != nil { + if !m.dryRun { + if err := m.dmOut.SetActionTriggers(acts[0].ID, acts, utils.NonTransactional); err != nil { return err } m.stats[utils.ActionTriggers] += 1 } } } - if m.dryRun != true { + if !m.dryRun { // All done, update version wtih current one vrs := engine.Versions{utils.ActionTriggers: engine.CurrentDataDBVersions()[utils.ActionTriggers]} - if err = m.dm.DataDB().SetVersions(vrs, false); err != nil { + if err = m.dmOut.DataDB().SetVersions(vrs, false); err != nil { return utils.NewCGRError(utils.Migrator, utils.ServerErrorCaps, err.Error(), @@ -90,10 +113,42 @@ func (m *Migrator) migrateActionTriggers() (err error) { return } +func (m *Migrator) migrateActionTriggers() (err error) { + var vrs engine.Versions + current := engine.CurrentDataDBVersions() + vrs, err = m.dmOut.DataDB().GetVersions(utils.TBLVersions) + if err != nil { + return utils.NewCGRError(utils.Migrator, + utils.ServerErrorCaps, + err.Error(), + fmt.Sprintf("error: <%s> when querying oldDataDB for versions", err.Error())) + } else if len(vrs) == 0 { + return utils.NewCGRError(utils.Migrator, + utils.MandatoryIEMissingCaps, + utils.UndefinedVersion, + "version number is not defined for ActionTriggers model") + } + switch vrs[utils.ActionTriggers] { + case current[utils.ActionTriggers]: + if m.sameDBname { + return + } + if err := m.migrateCurrentActionTrigger(); err != nil { + return err + } + return + + case 1: + if err := m.migrateV1ActionTrigger(); err != nil { + return err + } + } + return +} + func (v1Act v1ActionTrigger) AsActionTrigger() (at *engine.ActionTrigger) { at = &engine.ActionTrigger{ - ID: v1Act.Id, - // UniqueID: utils.GenUUID(), + ID: v1Act.Id, ThresholdType: v1Act.ThresholdType, ThresholdValue: v1Act.ThresholdValue, Recurrent: v1Act.Recurrent, diff --git a/migrator/alias.go b/migrator/alias.go new file mode 100644 index 000000000..5ce192c1f --- /dev/null +++ b/migrator/alias.go @@ -0,0 +1,134 @@ +/* +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" + "strings" + + "github.com/cgrates/cgrates/engine" + "github.com/cgrates/cgrates/utils" +) + +func (m *Migrator) migrateCurrentAlias() (err error) { + var ids []string + ids, err = m.dmIN.DataDB().GetKeysForPrefix(utils.ALIASES_PREFIX) + if err != nil { + return err + } + for _, id := range ids { + idg := strings.TrimPrefix(id, utils.ALIASES_PREFIX) + usr, err := m.dmIN.DataDB().GetAlias(idg, true, utils.NonTransactional) + if err != nil { + return err + } + if usr != nil { + if m.dryRun != true { + if err := m.dmOut.DataDB().SetAlias(usr, utils.NonTransactional); err != nil { + return err + } + } + } + } + return +} + +func (m *Migrator) migrateCurrentReverseAlias() (err error) { + var ids []string + ids, err = m.dmIN.DataDB().GetKeysForPrefix(utils.REVERSE_ALIASES_PREFIX) + if err != nil { + return err + } + for _, id := range ids { + idg := strings.TrimPrefix(id, utils.REVERSE_ALIASES_PREFIX) + + usrs, err := m.dmIN.DataDB().GetReverseAlias(idg, true, utils.NonTransactional) + if err != nil { + return err + } + for _, usr := range usrs { + alias, err := m.dmIN.DataDB().GetAlias(usr, true, utils.NonTransactional) + if err != nil { + return err + } + if alias != nil { + if err := m.dmOut.DataDB().SetReverseAlias(alias, utils.NonTransactional); err != nil { + return err + } + } + } + } + return +} + +func (m *Migrator) migrateAlias() (err error) { + var vrs engine.Versions + current := engine.CurrentDataDBVersions() + vrs, err = m.dmOut.DataDB().GetVersions(utils.TBLVersions) + if err != nil { + return utils.NewCGRError(utils.Migrator, + utils.ServerErrorCaps, + err.Error(), + fmt.Sprintf("error: <%s> when querying oldDataDB for versions", err.Error())) + } else if len(vrs) == 0 { + return utils.NewCGRError(utils.Migrator, + utils.MandatoryIEMissingCaps, + utils.UndefinedVersion, + "version number is not defined for ActionTriggers model") + } + switch vrs[utils.Alias] { + case current[utils.Alias]: + if m.sameDBname { + return + } + if err := m.migrateCurrentAlias(); err != nil { + return err + } + return + } + return +} + +func (m *Migrator) migrateReverseAlias() (err error) { + var vrs engine.Versions + current := engine.CurrentDataDBVersions() + vrs, err = m.dmOut.DataDB().GetVersions(utils.TBLVersions) + if err != nil { + return utils.NewCGRError(utils.Migrator, + utils.ServerErrorCaps, + err.Error(), + fmt.Sprintf("error: <%s> when querying oldDataDB for versions", err.Error())) + } else if len(vrs) == 0 { + return utils.NewCGRError(utils.Migrator, + utils.MandatoryIEMissingCaps, + utils.UndefinedVersion, + "version number is not defined for ActionTriggers model") + } + switch vrs[utils.ReverseAlias] { + case current[utils.ReverseAlias]: + if m.sameDBname { + return + } + if err := m.migrateCurrentReverseAlias(); err != nil { + return err + } + return + } + return +} diff --git a/migrator/cdrstats.go b/migrator/cdrstats.go new file mode 100644 index 000000000..54469b625 --- /dev/null +++ b/migrator/cdrstats.go @@ -0,0 +1,71 @@ +/* +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) migrateCurrentCdrStats() (err error) { + cdrsts, err := m.dmIN.GetAllCdrStats() + if err != nil { + return err + } + for _, cdrst := range cdrsts { + if cdrst != nil { + if m.dryRun != true { + if err := m.dmOut.SetCdrStats(cdrst); err != nil { + return err + } + } + } + } + return +} + +func (m *Migrator) migrateCdrStats() (err error) { + var vrs engine.Versions + current := engine.CurrentDataDBVersions() + vrs, err = m.dmOut.DataDB().GetVersions(utils.TBLVersions) + if err != nil { + return utils.NewCGRError(utils.Migrator, + utils.ServerErrorCaps, + err.Error(), + fmt.Sprintf("error: <%s> when querying oldDataDB for versions", err.Error())) + } else if len(vrs) == 0 { + return utils.NewCGRError(utils.Migrator, + utils.MandatoryIEMissingCaps, + utils.UndefinedVersion, + "version number is not defined for ActionTriggers model") + } + switch vrs[utils.CdrStats] { + case current[utils.CdrStats]: + if m.sameDBname { + return + } + if err := m.migrateCurrentCdrStats(); err != nil { + return err + } + return + } + return +} diff --git a/migrator/derived_chargers.go b/migrator/derived_chargers.go new file mode 100644 index 000000000..4309a27b9 --- /dev/null +++ b/migrator/derived_chargers.go @@ -0,0 +1,78 @@ +/* +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" + "strings" + + "github.com/cgrates/cgrates/engine" + "github.com/cgrates/cgrates/utils" +) + +func (m *Migrator) migrateCurrentDerivedChargers() (err error) { + var ids []string + ids, err = m.dmIN.DataDB().GetKeysForPrefix(utils.DERIVEDCHARGERS_PREFIX) + if err != nil { + return err + } + for _, id := range ids { + idg := strings.TrimPrefix(id, utils.DERIVEDCHARGERS_PREFIX) + drc, err := m.dmIN.GetDerivedChargers(idg, true, utils.NonTransactional) + if err != nil { + return err + } + if drc != nil { + if m.dryRun != true { + if err := m.dmOut.DataDB().SetDerivedChargers(id, drc, utils.NonTransactional); err != nil { + return err + } + } + } + } + return +} + +func (m *Migrator) migrateDerivedChargers() (err error) { + var vrs engine.Versions + current := engine.CurrentDataDBVersions() + vrs, err = m.dmOut.DataDB().GetVersions(utils.TBLVersions) + if err != nil { + return utils.NewCGRError(utils.Migrator, + utils.ServerErrorCaps, + err.Error(), + fmt.Sprintf("error: <%s> when querying oldDataDB for versions", err.Error())) + } else if len(vrs) == 0 { + return utils.NewCGRError(utils.Migrator, + utils.MandatoryIEMissingCaps, + utils.UndefinedVersion, + "version number is not defined for ActionTriggers model") + } + switch vrs[utils.DerivedChargersV] { + case current[utils.DerivedChargersV]: + if m.sameDBname { + return + } + if err := m.migrateCurrentDerivedChargers(); err != nil { + return err + } + return + } + return +} diff --git a/migrator/destinations.go b/migrator/destinations.go new file mode 100644 index 000000000..afb94fba0 --- /dev/null +++ b/migrator/destinations.go @@ -0,0 +1,132 @@ +/* +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" + "strings" + + "github.com/cgrates/cgrates/engine" + "github.com/cgrates/cgrates/utils" +) + +func (m *Migrator) migrateCurrentDestinations() (err error) { + var ids []string + ids, err = m.dmIN.DataDB().GetKeysForPrefix(utils.DESTINATION_PREFIX) + if err != nil { + return err + } + for _, id := range ids { + idg := strings.TrimPrefix(id, utils.DESTINATION_PREFIX) + dst, err := m.dmIN.DataDB().GetDestination(idg, true, utils.NonTransactional) + if err != nil { + return err + } + if dst != nil { + if m.dryRun != true { + if err := m.dmOut.DataDB().SetDestination(dst, utils.NonTransactional); err != nil { + return err + } + } + } + } + return +} + +func (m *Migrator) migrateDestinations() (err error) { + var vrs engine.Versions + current := engine.CurrentDataDBVersions() + vrs, err = m.dmOut.DataDB().GetVersions(utils.TBLVersions) + if err != nil { + return utils.NewCGRError(utils.Migrator, + utils.ServerErrorCaps, + err.Error(), + fmt.Sprintf("error: <%s> when querying oldDataDB for versions", err.Error())) + } else if len(vrs) == 0 { + return utils.NewCGRError(utils.Migrator, + utils.MandatoryIEMissingCaps, + utils.UndefinedVersion, + "version number is not defined for ActionTriggers model") + } + switch vrs[utils.Destinations] { + case current[utils.Destinations]: + if m.sameDBname { + return + } + if err := m.migrateCurrentDestinations(); err != nil { + return err + } + return + } + return +} + +func (m *Migrator) migrateCurrentReverseDestinations() (err error) { + var ids []string + ids, err = m.dmIN.DataDB().GetKeysForPrefix(utils.REVERSE_DESTINATION_PREFIX) + if err != nil { + return err + } + for _, id := range ids { + rdst, err := m.dmIN.DataDB().GetReverseDestination(id, true, utils.NonTransactional) + if err != nil { + return err + } + for _, id := range rdst { + rdst, err := m.dmIN.DataDB().GetDestination(id, true, utils.NonTransactional) + if err != nil { + return err + } + if rdst != nil { + if err := m.dmOut.DataDB().SetReverseDestination(rdst, utils.NonTransactional); err != nil { + return err + } + } + } + } + return +} + +func (m *Migrator) migrateReverseDestinations() (err error) { + var vrs engine.Versions + current := engine.CurrentDataDBVersions() + vrs, err = m.dmOut.DataDB().GetVersions(utils.TBLVersions) + if err != nil { + return utils.NewCGRError(utils.Migrator, + utils.ServerErrorCaps, + err.Error(), + fmt.Sprintf("error: <%s> when querying oldDataDB for versions", err.Error())) + } else if len(vrs) == 0 { + return utils.NewCGRError(utils.Migrator, + utils.MandatoryIEMissingCaps, + utils.UndefinedVersion, + "version number is not defined for ActionTriggers model") + } + switch vrs[utils.ReverseDestinations] { + case current[utils.ReverseDestinations]: + if m.sameDBname { + return + } + if err := m.migrateCurrentReverseDestinations(); err != nil { + return err + } + return + } + return +} diff --git a/migrator/lcr.go b/migrator/lcr.go new file mode 100644 index 000000000..450c31c91 --- /dev/null +++ b/migrator/lcr.go @@ -0,0 +1,78 @@ +/* +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" + "strings" + + "github.com/cgrates/cgrates/engine" + "github.com/cgrates/cgrates/utils" +) + +func (m *Migrator) migrateCurrentLCR() (err error) { + var ids []string + ids, err = m.dmIN.DataDB().GetKeysForPrefix(utils.LCR_PREFIX) + if err != nil { + return err + } + for _, id := range ids { + idg := strings.TrimPrefix(id, utils.LCR_PREFIX) + lcr, err := m.dmIN.GetLCR(idg, true, utils.NonTransactional) + if err != nil { + return err + } + if lcr != nil { + if m.dryRun != true { + if err := m.dmOut.SetLCR(lcr, utils.NonTransactional); err != nil { + return err + } + } + } + } + return +} + +func (m *Migrator) migrateLCR() (err error) { + var vrs engine.Versions + current := engine.CurrentDataDBVersions() + vrs, err = m.dmOut.DataDB().GetVersions(utils.TBLVersions) + if err != nil { + return utils.NewCGRError(utils.Migrator, + utils.ServerErrorCaps, + err.Error(), + fmt.Sprintf("error: <%s> when querying oldDataDB for versions", err.Error())) + } else if len(vrs) == 0 { + return utils.NewCGRError(utils.Migrator, + utils.MandatoryIEMissingCaps, + utils.UndefinedVersion, + "version number is not defined for ActionTriggers model") + } + switch vrs[utils.LCR] { + case current[utils.LCR]: + if m.sameDBname { + return + } + if err := m.migrateCurrentLCR(); err != nil { + return err + } + return + } + return +} diff --git a/migrator/migrator.go b/migrator/migrator.go index 4f1647e71..81c86f155 100755 --- a/migrator/migrator.go +++ b/migrator/migrator.go @@ -26,7 +26,7 @@ import ( "github.com/cgrates/cgrates/utils" ) -func NewMigrator(dm *engine.DataManager, dataDBType, dataDBEncoding string, storDB engine.Storage, storDBType string, oldDataDB V1DataDB, oldDataDBType, oldDataDBEncoding string, oldStorDB engine.Storage, oldStorDBType string, dryRun bool) (m *Migrator, err error) { +func NewMigrator(dmIN *engine.DataManager, dmOut *engine.DataManager, dataDBType, dataDBEncoding string, storDB engine.Storage, storDBType string, oldDataDB MigratorDataDB, oldDataDBType, oldDataDBEncoding string, oldStorDB engine.Storage, oldStorDBType string, dryRun bool, sameDBname bool) (m *Migrator, err error) { var mrshlr engine.Marshaler var oldmrshlr engine.Marshaler if dataDBEncoding == utils.MSGPACK { @@ -41,27 +41,30 @@ func NewMigrator(dm *engine.DataManager, dataDBType, dataDBEncoding string, stor stats := make(map[string]int) m = &Migrator{ - dm: dm, dataDBType: dataDBType, - storDB: storDB, storDBType: storDBType, mrshlr: mrshlr, + dmOut: dmOut, dataDBType: dataDBType, + storDB: storDB, storDBType: storDBType, + mrshlr: mrshlr, dmIN: dmIN, oldDataDB: oldDataDB, oldDataDBType: oldDataDBType, oldStorDB: oldStorDB, oldStorDBType: oldStorDBType, - oldmrshlr: oldmrshlr, dryRun: dryRun, stats: stats, + oldmrshlr: oldmrshlr, dryRun: dryRun, sameDBname: sameDBname, stats: stats, } return m, err } type Migrator struct { - dm *engine.DataManager + dmIN *engine.DataManager //oldatadb + dmOut *engine.DataManager dataDBType string storDB engine.Storage storDBType string mrshlr engine.Marshaler - oldDataDB V1DataDB + oldDataDB MigratorDataDB oldDataDBType string oldStorDB engine.Storage oldStorDBType string oldmrshlr engine.Marshaler dryRun bool + sameDBname bool stats map[string]int } @@ -84,7 +87,7 @@ func (m *Migrator) Migrate(taskIDs []string) (err error, stats map[string]int) { err.Error(), fmt.Sprintf("error: <%s> when updating CostDetails version into StorDB", err.Error())), nil } - if err := m.dm.DataDB().SetVersions(engine.CurrentDBVersions(m.dataDBType), true); err != nil { + if err := m.dmOut.DataDB().SetVersions(engine.CurrentDBVersions(m.dataDBType), true); err != nil { return utils.NewCGRError(utils.Migrator, utils.ServerErrorCaps, err.Error(), @@ -108,7 +111,224 @@ func (m *Migrator) Migrate(taskIDs []string) (err error, stats map[string]int) { case utils.MetaStats: err = m.migrateStats() case utils.MetaThresholds: - err = m.migrateStats() + err = m.migrateThresholds() + //only Move + case utils.MetaRatingPlans: + err = m.migrateRatingPlans() + case utils.MetaRatingProfile: + err = m.migrateRatingProfiles() + case utils.MetaDestinations: + err = m.migrateDestinations() + case utils.MetaReverseDestinations: + err = m.migrateReverseDestinations() + case utils.MetaLCR: + err = m.migrateLCR() + case utils.MetaCdrStats: + err = m.migrateCdrStats() + case utils.MetaTiming: + err = m.migrateTimings() + case utils.MetaRQF: + err = m.migrateRequestFilter() + case utils.MetaResource: + err = m.migrateResources() + case utils.MetaReverseAlias: + err = m.migrateReverseAlias() + case utils.MetaAlias: + err = m.migrateAlias() + case utils.MetaUser: + err = m.migrateUser() + case utils.MetaSubscribers: + err = m.migrateSubscribers() + case utils.MetaDerivedChargersV: + err = m.migrateDerivedChargers() + //TPS + case utils.MetaTpRatingPlans: + err = m.migrateTPratingplans() + case utils.MetaTpLcrs: + err = m.migrateTPlcrs() + case utils.MetaTpFilters: + err = m.migrateTPfilters() + case utils.MetaTpDestinationRates: + err = m.migrateTPdestinationrates() + case utils.MetaTpActionTriggers: + err = m.migrateTPactiontriggers() + case utils.MetaTpAccountActions: + err = m.migrateTPaccountacction() + case utils.MetaTpActionPlans: + err = m.migrateTPactionplans() + case utils.MetaTpActions: + err = m.migrateTPactions() + case utils.MetaTpDerivedCharges: + err = m.migrateTPderivedchargers() + case utils.MetaTpThresholds: + err = m.migrateTPthresholds() + case utils.MetaTpStats: + err = m.migrateTPstats() + case utils.MetaTpSharedGroups: + err = m.migrateTPsharedgroups() + case utils.MetaTpRatingProfiles: + err = m.migrateTPratingprofiles() + case utils.MetaTpResources: + err = m.migrateTPresources() + case utils.MetaTpRates: + err = m.migrateTPrates() + case utils.MetaTpTiming: + err = m.migrateTpTimings() + case utils.MetaTpAliases: + err = m.migrateTPaliases() + case utils.MetaTpUsers: + err = m.migrateTPusers() + case utils.MetaTpDerivedChargersV: + err = m.migrateTPderivedchargers() + case utils.MetaTpCdrStats: + err = m.migrateTPcdrstats() + case utils.MetaTpDestinations: + err = m.migrateTPDestinations() + case utils.MetaTpRatingPlan: + err = m.migrateTPratingplans() + case utils.MetaTpRatingProfile: + err = m.migrateTPfilters() + //DATADB ALL + case utils.MetaDataDB: + if err = m.migrateCostDetails(); err != nil { + log.Print(err) + } + if err := m.migrateAccounts(); err != nil { + log.Print(err) + } + if err := m.migrateActionPlans(); err != nil { + log.Print(err) + } + if err := m.migrateActionTriggers(); err != nil { + log.Print(err) + } + if err := m.migrateActions(); err != nil { + log.Print(err) + } + if err := m.migrateSharedGroups(); err != nil { + log.Print(err) + } + if err := m.migrateStats(); err != nil { + log.Print(err) + } + if err := m.migrateThresholds(); err != nil { + log.Print(err) + } + if err := m.migrateRatingPlans(); err != nil { + log.Print(err) + } + if err := m.migrateRatingProfiles(); err != nil { + log.Print(err) + } + if err := m.migrateDestinations(); err != nil { + log.Print(err) + } + if err := m.migrateReverseDestinations(); err != nil { + log.Print(err) + } + if err := m.migrateLCR(); err != nil { + log.Print(err) + } + if err := m.migrateCdrStats(); err != nil { + log.Print(err) + } + if err := m.migrateTimings(); err != nil { + log.Print(err) + } + if err := m.migrateRequestFilter(); err != nil { + log.Print(err) + } + if err := m.migrateResources(); err != nil { + log.Print(err) + } + if err := m.migrateReverseAlias(); err != nil { + log.Print(err) + } + if err := m.migrateAlias(); err != nil { + log.Print(err) + } + if err := m.migrateUser(); err != nil { + log.Print(err) + } + if err := m.migrateSubscribers(); err != nil { + log.Print(err) + } + if err := m.migrateDerivedChargers(); err != nil { + log.Print(err) + } + err = nil + //STORDB ALL + case utils.MetaStorDB: + if err := m.migrateTPratingplans(); err != nil { + log.Print(err) + } + if err := m.migrateTPlcrs(); err != nil { + log.Print(err) + } + if err := m.migrateTPfilters(); err != nil { + log.Print(err) + } + if err := m.migrateTPdestinationrates(); err != nil { + log.Print(err) + } + if err := m.migrateTPactiontriggers(); err != nil { + log.Print(err) + } + if err := m.migrateTPaccountacction(); err != nil { + log.Print(err) + } + if err := m.migrateTPactionplans(); err != nil { + log.Print(err) + } + if err := m.migrateTPactions(); err != nil { + log.Print(err) + } + if err := m.migrateTPderivedchargers(); err != nil { + log.Print(err) + } + if err := m.migrateTPthresholds(); err != nil { + log.Print(err) + } + if err := m.migrateTPstats(); err != nil { + log.Print(err) + } + if err := m.migrateTPsharedgroups(); err != nil { + log.Print(err) + } + if err := m.migrateTPratingprofiles(); err != nil { + log.Print(err) + } + if err := m.migrateTPresources(); err != nil { + log.Print(err) + } + if err := m.migrateTPrates(); err != nil { + log.Print(err) + } + if err := m.migrateTpTimings(); err != nil { + log.Print(err) + } + if err := m.migrateTPaliases(); err != nil { + log.Print(err) + } + if err := m.migrateTPusers(); err != nil { + log.Print(err) + } + if err := m.migrateTPderivedchargers(); err != nil { + log.Print(err) + } + if err := m.migrateTPcdrstats(); err != nil { + log.Print(err) + } + if err := m.migrateTPDestinations(); err != nil { + log.Print(err) + } + if err := m.migrateTPratingplans(); err != nil { + log.Print(err) + } + if err := m.migrateTPfilters(); err != nil { + log.Print(err) + } + err = nil } } for k, v := range m.stats { diff --git a/migrator/v1datadb.go b/migrator/migratorDataDB.go similarity index 97% rename from migrator/v1datadb.go rename to migrator/migratorDataDB.go index 9719472fd..f0cc18acb 100644 --- a/migrator/v1datadb.go +++ b/migrator/migratorDataDB.go @@ -18,7 +18,7 @@ along with this program. If not, see package migrator -type V1DataDB interface { +type MigratorDataDB interface { getKeysForPrefix(prefix string) ([]string, error) getv1Account() (v1Acnt *v1Account, err error) setV1Account(x *v1Account) (err error) diff --git a/migrator/migrator_it_test.go b/migrator/migrator_it_test.go index f4a0aa13a..a33eded24 100644 --- a/migrator/migrator_it_test.go +++ b/migrator/migrator_it_test.go @@ -30,6 +30,7 @@ import ( ) var ( + Move = "move" dbtype string mig *Migrator dataDir = flag.String("data_dir", "/usr/share/cgrates", "CGR data dir path here") @@ -45,6 +46,7 @@ var sTestsITMigrator = []func(t *testing.T){ testMigratorActions, testMigratorSharedGroups, testMigratorStats, + testMigratorTPRatingProfile, testFlush, } @@ -58,6 +60,10 @@ func TestMigratorITPostgresConnect(t *testing.T) { if err != nil { log.Fatal(err) } + dataDB2, err := engine.ConfigureDataStorage(postgresITCfg.DataDbType, postgresITCfg.DataDbHost, postgresITCfg.DataDbPort, postgresITCfg.DataDbName, postgresITCfg.DataDbUser, postgresITCfg.DataDbPass, postgresITCfg.DBDataEncoding, postgresITCfg.CacheConfig, *loadHistorySize) + if err != nil { + log.Fatal(err) + } oldDataDB, err := ConfigureV1DataStorage(postgresITCfg.DataDbType, postgresITCfg.DataDbHost, postgresITCfg.DataDbPort, postgresITCfg.DataDbName, postgresITCfg.DataDbUser, postgresITCfg.DataDbPass, postgresITCfg.DBDataEncoding) if err != nil { log.Fatal(err) @@ -72,7 +78,7 @@ func TestMigratorITPostgresConnect(t *testing.T) { if err != nil { log.Fatal(err) } - mig, err = NewMigrator(dataDB, postgresITCfg.DataDbType, postgresITCfg.DBDataEncoding, storDB, postgresITCfg.StorDBType, oldDataDB, postgresITCfg.DataDbType, postgresITCfg.DBDataEncoding, oldstorDB, postgresITCfg.StorDBType, false) + mig, err = NewMigrator(dataDB, dataDB2, postgresITCfg.DataDbType, postgresITCfg.DBDataEncoding, storDB, postgresITCfg.StorDBType, oldDataDB, postgresITCfg.DataDbType, postgresITCfg.DBDataEncoding, oldstorDB, postgresITCfg.StorDBType, false, true) if err != nil { log.Fatal(err) } @@ -96,6 +102,10 @@ func TestMigratorITRedisConnect(t *testing.T) { if err != nil { log.Fatal(err) } + dataDB2, err := engine.ConfigureDataStorage(mysqlITCfg.DataDbType, mysqlITCfg.DataDbHost, mysqlITCfg.DataDbPort, mysqlITCfg.DataDbName, mysqlITCfg.DataDbUser, mysqlITCfg.DataDbPass, mysqlITCfg.DBDataEncoding, mysqlITCfg.CacheConfig, *loadHistorySize) + if err != nil { + log.Fatal(err) + } oldDataDB, err := ConfigureV1DataStorage(mysqlITCfg.DataDbType, mysqlITCfg.DataDbHost, mysqlITCfg.DataDbPort, mysqlITCfg.DataDbName, mysqlITCfg.DataDbUser, mysqlITCfg.DataDbPass, mysqlITCfg.DBDataEncoding) if err != nil { log.Fatal(err) @@ -110,7 +120,7 @@ func TestMigratorITRedisConnect(t *testing.T) { if err != nil { log.Fatal(err) } - mig, err = NewMigrator(dataDB, mysqlITCfg.DataDbType, mysqlITCfg.DBDataEncoding, storDB, mysqlITCfg.StorDBType, oldDataDB, mysqlITCfg.DataDbType, mysqlITCfg.DBDataEncoding, oldstorDB, mysqlITCfg.StorDBType, false) + mig, err = NewMigrator(dataDB, dataDB2, mysqlITCfg.DataDbType, mysqlITCfg.DBDataEncoding, storDB, mysqlITCfg.StorDBType, oldDataDB, mysqlITCfg.DataDbType, mysqlITCfg.DBDataEncoding, oldstorDB, mysqlITCfg.StorDBType, false, true) if err != nil { log.Fatal(err) } @@ -134,6 +144,10 @@ func TestMigratorITMongoConnect(t *testing.T) { if err != nil { log.Fatal(err) } + dataDB2, err := engine.ConfigureDataStorage(mgoITCfg.DataDbType, mgoITCfg.DataDbHost, mgoITCfg.DataDbPort, mgoITCfg.DataDbName, mgoITCfg.DataDbUser, mgoITCfg.DataDbPass, mgoITCfg.DBDataEncoding, mgoITCfg.CacheConfig, *loadHistorySize) + if err != nil { + log.Fatal(err) + } oldDataDB, err := ConfigureV1DataStorage(mgoITCfg.DataDbType, mgoITCfg.DataDbHost, mgoITCfg.DataDbPort, mgoITCfg.DataDbName, mgoITCfg.DataDbUser, mgoITCfg.DataDbPass, mgoITCfg.DBDataEncoding) if err != nil { log.Fatal(err) @@ -148,7 +162,7 @@ func TestMigratorITMongoConnect(t *testing.T) { if err != nil { log.Fatal(err) } - mig, err = NewMigrator(dataDB, mgoITCfg.DataDbType, mgoITCfg.DBDataEncoding, storDB, mgoITCfg.StorDBType, oldDataDB, mgoITCfg.DataDbType, mgoITCfg.DBDataEncoding, oldstorDB, mgoITCfg.StorDBType, false) + mig, err = NewMigrator(dataDB, dataDB2, mgoITCfg.DataDbType, mgoITCfg.DBDataEncoding, storDB, mgoITCfg.StorDBType, oldDataDB, mgoITCfg.DataDbType, mgoITCfg.DBDataEncoding, oldstorDB, mgoITCfg.StorDBType, false, true) if err != nil { log.Fatal(err) } @@ -162,9 +176,56 @@ func TestMigratorITMongo(t *testing.T) { } } +func TestMigratorITMoveConnect(t *testing.T) { + cdrsMongoCfgPath := path.Join(*dataDir, "conf", "samples", "tutmongo") + mgoITCfg, err := config.NewCGRConfigFromFolder(cdrsMongoCfgPath) + if err != nil { + t.Fatal(err) + } + cdrsMysqlCfgPath := path.Join(*dataDir, "conf", "samples", "tutmysql") + mysqlITCfg, err := config.NewCGRConfigFromFolder(cdrsMysqlCfgPath) + if err != nil { + t.Fatal(err) + } + dataDB, err := engine.ConfigureDataStorage(mgoITCfg.DataDbType, mgoITCfg.DataDbHost, mgoITCfg.DataDbPort, mgoITCfg.DataDbName, mgoITCfg.DataDbUser, mgoITCfg.DataDbPass, mgoITCfg.DBDataEncoding, mgoITCfg.CacheConfig, *loadHistorySize) + if err != nil { + log.Fatal(err) + } + dataDB2, err := engine.ConfigureDataStorage(mysqlITCfg.DataDbType, mysqlITCfg.DataDbHost, mysqlITCfg.DataDbPort, mysqlITCfg.DataDbName, mysqlITCfg.DataDbUser, mysqlITCfg.DataDbPass, mysqlITCfg.DBDataEncoding, mysqlITCfg.CacheConfig, *loadHistorySize) + if err != nil { + log.Fatal(err) + } + oldDataDB, err := ConfigureV1DataStorage(mysqlITCfg.DataDbType, mysqlITCfg.DataDbHost, mysqlITCfg.DataDbPort, mysqlITCfg.DataDbName, mysqlITCfg.DataDbUser, mysqlITCfg.DataDbPass, mysqlITCfg.DBDataEncoding) + if err != nil { + log.Fatal(err) + } + storDB, err := engine.ConfigureStorStorage(mgoITCfg.StorDBType, mgoITCfg.StorDBHost, mgoITCfg.StorDBPort, mgoITCfg.StorDBName, mgoITCfg.StorDBUser, mgoITCfg.StorDBPass, mgoITCfg.DBDataEncoding, + config.CgrConfig().StorDBMaxOpenConns, config.CgrConfig().StorDBMaxIdleConns, config.CgrConfig().StorDBConnMaxLifetime, config.CgrConfig().StorDBCDRSIndexes) + if err != nil { + log.Fatal(err) + } + oldstorDB, err := engine.ConfigureStorStorage(mysqlITCfg.StorDBType, mysqlITCfg.StorDBHost, mysqlITCfg.StorDBPort, mysqlITCfg.StorDBName, mysqlITCfg.StorDBUser, mysqlITCfg.StorDBPass, mysqlITCfg.DBDataEncoding, + config.CgrConfig().StorDBMaxOpenConns, config.CgrConfig().StorDBMaxIdleConns, config.CgrConfig().StorDBConnMaxLifetime, config.CgrConfig().StorDBCDRSIndexes) + if err != nil { + log.Fatal(err) + } + mig, err = NewMigrator(dataDB2, dataDB, mgoITCfg.DataDbType, mgoITCfg.DBDataEncoding, storDB, mgoITCfg.StorDBType, oldDataDB, mgoITCfg.DataDbType, mgoITCfg.DBDataEncoding, oldstorDB, mgoITCfg.StorDBType, false, false) + if err != nil { + log.Fatal(err) + } +} + +func TestMigratorITMove(t *testing.T) { + dbtype = Move + log.Print("Move") + for _, stest := range sTestsITMigrator { + t.Run("TestITMigratorOnMongo", stest) + } +} + func testFlush(t *testing.T) { - mig.dm.DataDB().Flush("") - if err := engine.SetDBVersions(mig.dm.DataDB()); err != nil { + mig.dmOut.DataDB().Flush("") + if err := engine.SetDBVersions(mig.dmOut.DataDB()); err != nil { t.Error("Error ", err.Error()) } @@ -184,11 +245,16 @@ func testMigratorAccounts(t *testing.T) { if err != nil { t.Error("Error when setting v1 acc ", err.Error()) } + currentVersion := engine.Versions{utils.StatS: 2, utils.Thresholds: 2, utils.Accounts: 1, utils.Actions: 2, utils.ActionTriggers: 2, utils.ActionPlans: 2, utils.SharedGroups: 2} + err = mig.dmOut.DataDB().SetVersions(currentVersion, false) + if err != nil { + t.Error("Error when setting version for stats ", err.Error()) + } err, _ = mig.Migrate([]string{utils.MetaAccounts}) if err != nil { t.Error("Error when migrating accounts ", err.Error()) } - result, err := mig.dm.DataDB().GetAccount(testAccount.ID) + result, err := mig.dmOut.DataDB().GetAccount(testAccount.ID) if err != nil { t.Error("Error when getting account ", err.Error()) } @@ -202,17 +268,42 @@ func testMigratorAccounts(t *testing.T) { if err != nil { t.Error("Error when marshaling ", err.Error()) } + currentVersion := engine.Versions{utils.StatS: 2, utils.Thresholds: 2, utils.Accounts: 1, utils.Actions: 2, utils.ActionTriggers: 2, utils.ActionPlans: 2, utils.SharedGroups: 2} + err = mig.dmOut.DataDB().SetVersions(currentVersion, false) + if err != nil { + t.Error("Error when setting version for stats ", err.Error()) + } err, _ = mig.Migrate([]string{utils.MetaAccounts}) if err != nil { t.Error("Error when migrating accounts ", err.Error()) } - result, err := mig.dm.DataDB().GetAccount(testAccount.ID) + result, err := mig.dmOut.DataDB().GetAccount(testAccount.ID) if err != nil { t.Error("Error when getting account ", err.Error()) } if !reflect.DeepEqual(testAccount, result) { t.Errorf("Expecting: %+v, received: %+v", testAccount, result) } + case dbtype == Move: + if err := mig.dmIN.DataDB().SetAccount(testAccount); err != nil { + log.Print("GOT ERR DMIN", err) + } + currentVersion := engine.CurrentDataDBVersions() + err := mig.dmOut.DataDB().SetVersions(currentVersion, false) + if err != nil { + t.Error("Error when setting version for stats ", err.Error()) + } + err, _ = mig.Migrate([]string{utils.MetaAccounts}) + if err != nil { + t.Error("Error when migrating accounts ", err.Error()) + } + result, err := mig.dmOut.DataDB().GetAccount(testAccount.ID) + if err != nil { + log.Print("GOT ERR DMOUT", err) + } + if !reflect.DeepEqual(testAccount, result) { + t.Errorf("Expecting: %+v, received: %+v", testAccount, result) + } } } @@ -225,11 +316,16 @@ func testMigratorActionPlans(t *testing.T) { if err != nil { t.Error("Error when setting v1 ActionPlan ", err.Error()) } + currentVersion := engine.Versions{utils.StatS: 2, utils.Thresholds: 2, utils.Accounts: 2, utils.Actions: 2, utils.ActionTriggers: 2, utils.ActionPlans: 1, utils.SharedGroups: 2} + err = mig.dmOut.DataDB().SetVersions(currentVersion, false) + if err != nil { + t.Error("Error when setting version for stats ", err.Error()) + } err, _ = mig.Migrate([]string{utils.MetaActionPlans}) if err != nil { t.Error("Error when migrating ActionPlans ", err.Error()) } - result, err := mig.dm.DataDB().GetActionPlan(ap.Id, true, utils.NonTransactional) + result, err := mig.dmOut.DataDB().GetActionPlan(ap.Id, true, utils.NonTransactional) if err != nil { t.Error("Error when getting ActionPlan ", err.Error()) } @@ -245,11 +341,40 @@ func testMigratorActionPlans(t *testing.T) { if err != nil { t.Error("Error when setting v1 ActionPlans ", err.Error()) } + currentVersion := engine.Versions{utils.StatS: 2, utils.Thresholds: 2, utils.Accounts: 2, utils.Actions: 2, utils.ActionTriggers: 2, utils.ActionPlans: 1, utils.SharedGroups: 2} + err = mig.dmOut.DataDB().SetVersions(currentVersion, false) + if err != nil { + t.Error("Error when setting version for stats ", err.Error()) + } err, _ = mig.Migrate([]string{utils.MetaActionPlans}) if err != nil { t.Error("Error when migrating ActionPlans ", err.Error()) } - result, err := mig.dm.DataDB().GetActionPlan(ap.Id, true, utils.NonTransactional) + result, err := mig.dmOut.DataDB().GetActionPlan(ap.Id, true, utils.NonTransactional) + if err != nil { + t.Error("Error when getting ActionPlan ", err.Error()) + } + if ap.Id != result.Id || !reflect.DeepEqual(ap.AccountIDs, result.AccountIDs) { + t.Errorf("Expecting: %+v, received: %+v", *ap, result) + } else if !reflect.DeepEqual(ap.ActionTimings[0].Timing, result.ActionTimings[0].Timing) { + t.Errorf("Expecting: %+v, received: %+v", ap.ActionTimings[0].Timing, result.ActionTimings[0].Timing) + } else if ap.ActionTimings[0].Weight != result.ActionTimings[0].Weight || ap.ActionTimings[0].ActionsID != result.ActionTimings[0].ActionsID { + t.Errorf("Expecting: %+v, received: %+v", ap.ActionTimings[0].Weight, result.ActionTimings[0].Weight) + } + case dbtype == Move: + if err := mig.dmIN.DataDB().SetActionPlan(ap.Id, ap, true, utils.NonTransactional); err != nil { + t.Error("Error when setting ActionPlan ", err.Error()) + } + currentVersion := engine.CurrentDataDBVersions() + err := mig.dmOut.DataDB().SetVersions(currentVersion, false) + if err != nil { + t.Error("Error when setting version for stats ", err.Error()) + } + err, _ = mig.Migrate([]string{utils.MetaActionPlans}) + if err != nil { + t.Error("Error when migrating ActionPlans ", err.Error()) + } + result, err := mig.dmOut.DataDB().GetActionPlan(ap.Id, true, utils.NonTransactional) if err != nil { t.Error("Error when getting ActionPlan ", err.Error()) } @@ -301,11 +426,16 @@ func testMigratorActionTriggers(t *testing.T) { if err != nil { t.Error("Error when setting v1 ActionTriggers ", err.Error()) } + currentVersion := engine.Versions{utils.StatS: 2, utils.Thresholds: 2, utils.Accounts: 2, utils.Actions: 2, utils.ActionTriggers: 1, utils.ActionPlans: 2, utils.SharedGroups: 2} + err = mig.dmOut.DataDB().SetVersions(currentVersion, false) + if err != nil { + t.Error("Error when setting version for stats ", err.Error()) + } err, _ = mig.Migrate([]string{utils.MetaActionTriggers}) if err != nil { t.Error("Error when migrating ActionTriggers ", err.Error()) } - result, err := mig.dm.GetActionTriggers((*v1atrs)[0].Id, true, utils.NonTransactional) + result, err := mig.dmOut.GetActionTriggers((*v1atrs)[0].Id, true, utils.NonTransactional) if err != nil { t.Error("Error when getting ActionTriggers ", err.Error()) } @@ -378,6 +508,86 @@ func testMigratorActionTriggers(t *testing.T) { t.Error("Error when migrating ActionTriggers ", err.Error()) } + case dbtype == Move: + if err := mig.dmIN.SetActionTriggers(atrs[0].ID, atrs, utils.NonTransactional); err != nil { + t.Error("Error when setting ActionPlan ", err.Error()) + } + currentVersion := engine.CurrentDataDBVersions() + err := mig.dmOut.DataDB().SetVersions(currentVersion, false) + if err != nil { + t.Error("Error when setting version for stats ", err.Error()) + } + err, _ = mig.Migrate([]string{utils.MetaActionTriggers}) + if err != nil { + t.Error("Error when migrating ActionPlans ", err.Error()) + } + result, err := mig.dmOut.GetActionTriggers(atrs[0].ID, true, utils.NonTransactional) + if err != nil { + t.Error("Error when getting ActionTriggers ", err.Error()) + } + if !reflect.DeepEqual(atrs[0].ID, result[0].ID) { + t.Errorf("Expecting: %+v, received: %+v", atrs[0].ID, result[0].ID) + } else if !reflect.DeepEqual(atrs[0].UniqueID, result[0].UniqueID) { + t.Errorf("Expecting: %+v, received: %+v", atrs[0].UniqueID, result[0].UniqueID) + } else if !reflect.DeepEqual(atrs[0].ThresholdType, result[0].ThresholdType) { + t.Errorf("Expecting: %+v, received: %+v", atrs[0].ThresholdType, result[0].ThresholdType) + } else if !reflect.DeepEqual(atrs[0].ThresholdValue, result[0].ThresholdValue) { + t.Errorf("Expecting: %+v, received: %+v", atrs[0].ThresholdValue, result[0].ThresholdValue) + } else if !reflect.DeepEqual(atrs[0].Recurrent, result[0].Recurrent) { + t.Errorf("Expecting: %+v, received: %+v", atrs[0].Recurrent, result[0].Recurrent) + } else if !reflect.DeepEqual(atrs[0].MinSleep, result[0].MinSleep) { + t.Errorf("Expecting: %+v, received: %+v", atrs[0].MinSleep, result[0].MinSleep) + } else if !reflect.DeepEqual(atrs[0].ExpirationDate, result[0].ExpirationDate) { + t.Errorf("Expecting: %+v, received: %+v", atrs[0].ExpirationDate, result[0].ExpirationDate) + } else if !reflect.DeepEqual(atrs[0].ActivationDate, result[0].ActivationDate) { + t.Errorf("Expecting: %+v, received: %+v", atrs[0].ActivationDate, result[0].ActivationDate) + } else if !reflect.DeepEqual(atrs[0].Balance.Type, result[0].Balance.Type) { + t.Errorf("Expecting: %+v, received: %+v", atrs[0].Balance.Type, result[0].Balance.Type) + } else if !reflect.DeepEqual(atrs[0].Weight, result[0].Weight) { + t.Errorf("Expecting: %+v, received: %+v", atrs[0].Weight, result[0].Weight) + } else if !reflect.DeepEqual(atrs[0].ActionsID, result[0].ActionsID) { + t.Errorf("Expecting: %+v, received: %+v", atrs[0].ActionsID, result[0].ActionsID) + } else if !reflect.DeepEqual(atrs[0].MinQueuedItems, result[0].MinQueuedItems) { + t.Errorf("Expecting: %+v, received: %+v", atrs[0].MinQueuedItems, result[0].MinQueuedItems) + } else if !reflect.DeepEqual(atrs[0].Executed, result[0].Executed) { + t.Errorf("Expecting: %+v, received: %+v", atrs[0].Executed, result[0].Executed) + } else if !reflect.DeepEqual(atrs[0].LastExecutionTime, result[0].LastExecutionTime) { + t.Errorf("Expecting: %+v, received: %+v", atrs[0].LastExecutionTime, result[0].LastExecutionTime) + } + //Testing each field of balance + if !reflect.DeepEqual(atrs[0].Balance.Uuid, result[0].Balance.Uuid) { + t.Errorf("Expecting: %+v, received: %+v", atrs[0].Balance.Uuid, result[0].Balance.Uuid) + } else if !reflect.DeepEqual(atrs[0].Balance.ID, result[0].Balance.ID) { + t.Errorf("Expecting: %+v, received: %+v", atrs[0].Balance.ID, result[0].Balance.ID) + } else if !reflect.DeepEqual(atrs[0].Balance.Type, result[0].Balance.Type) { + t.Errorf("Expecting: %+v, received: %+v", atrs[0].Balance.Type, result[0].Balance.Type) + } else if !reflect.DeepEqual(atrs[0].Balance.Value, result[0].Balance.Value) { + t.Errorf("Expecting: %+v, received: %+v", atrs[0].Balance.Value, result[0].Balance.Value) + } else if !reflect.DeepEqual(atrs[0].Balance.Directions, result[0].Balance.Directions) { + t.Errorf("Expecting: %+v, received: %+v", atrs[0].Balance.Directions, result[0].Balance.Directions) + } else if !reflect.DeepEqual(atrs[0].Balance.ExpirationDate, result[0].Balance.ExpirationDate) { + t.Errorf("Expecting: %+v, received: %+v", atrs[0].Balance.ExpirationDate, result[0].Balance.ExpirationDate) + } else if !reflect.DeepEqual(atrs[0].Balance.Weight, result[0].Balance.Weight) { + t.Errorf("Expecting: %+v, received: %+v", atrs[0].Balance.Weight, result[0].Balance.Weight) + } else if !reflect.DeepEqual(atrs[0].Balance.DestinationIDs, result[0].Balance.DestinationIDs) { + t.Errorf("Expecting: %+v, received: %+v", atrs[0].Balance.DestinationIDs, result[0].Balance.DestinationIDs) + } else if !reflect.DeepEqual(atrs[0].Balance.RatingSubject, result[0].Balance.RatingSubject) { + t.Errorf("Expecting: %+v, received: %+v", atrs[0].Balance.RatingSubject, result[0].Balance.RatingSubject) + } else if !reflect.DeepEqual(atrs[0].Balance.Categories, result[0].Balance.Categories) { + t.Errorf("Expecting: %+v, received: %+v", atrs[0].Balance.Categories, result[0].Balance.Categories) + } else if !reflect.DeepEqual(atrs[0].Balance.SharedGroups, result[0].Balance.SharedGroups) { + t.Errorf("Expecting: %+v, received: %+v", atrs[0].Balance.SharedGroups, result[0].Balance.SharedGroups) + } else if !reflect.DeepEqual(atrs[0].Balance.TimingIDs, result[0].Balance.TimingIDs) { + t.Errorf("Expecting: %+v, received: %+v", atrs[0].Balance.TimingIDs, result[0].Balance.TimingIDs) + } else if !reflect.DeepEqual(atrs[0].Balance.TimingIDs, result[0].Balance.TimingIDs) { + t.Errorf("Expecting: %+v, received: %+v", atrs[0].Balance.Timings, result[0].Balance.Timings) + } else if !reflect.DeepEqual(atrs[0].Balance.Disabled, result[0].Balance.Disabled) { + t.Errorf("Expecting: %+v, received: %+v", atrs[0].Balance.Disabled, result[0].Balance.Disabled) + } else if !reflect.DeepEqual(atrs[0].Balance.Factor, result[0].Balance.Factor) { + t.Errorf("Expecting: %+v, received: %+v", atrs[0].Balance.Factor, result[0].Balance.Factor) + } else if !reflect.DeepEqual(atrs[0].Balance.Blocker, result[0].Balance.Blocker) { + t.Errorf("Expecting: %+v, received: %+v", atrs[0].Balance.Blocker, result[0].Balance.Blocker) + } } } @@ -390,11 +600,16 @@ func testMigratorActions(t *testing.T) { if err != nil { t.Error("Error when setting v1 Actions ", err.Error()) } + currentVersion := engine.Versions{utils.StatS: 2, utils.Thresholds: 2, utils.Accounts: 2, utils.Actions: 1, utils.ActionTriggers: 2, utils.ActionPlans: 2, utils.SharedGroups: 2} + err = mig.dmOut.DataDB().SetVersions(currentVersion, false) + if err != nil { + t.Error("Error when setting version for stats ", err.Error()) + } err, _ = mig.Migrate([]string{utils.MetaActions}) if err != nil { t.Error("Error when migrating Actions ", err.Error()) } - result, err := mig.dm.GetActions((*v1act)[0].Id, true, utils.NonTransactional) + result, err := mig.dmOut.GetActions((*v1act)[0].Id, true, utils.NonTransactional) if err != nil { t.Error("Error when getting Actions ", err.Error()) } @@ -407,17 +622,42 @@ func testMigratorActions(t *testing.T) { if err != nil { t.Error("Error when setting v1 Actions ", err.Error()) } + currentVersion := engine.Versions{utils.StatS: 2, utils.Thresholds: 2, utils.Accounts: 2, utils.Actions: 1, utils.ActionTriggers: 2, utils.ActionPlans: 2, utils.SharedGroups: 2} + err = mig.dmOut.DataDB().SetVersions(currentVersion, false) + if err != nil { + t.Error("Error when setting version for stats ", err.Error()) + } err, _ = mig.Migrate([]string{utils.MetaActions}) if err != nil { t.Error("Error when migrating Actions ", err.Error()) } - result, err := mig.dm.GetActions((*v1act)[0].Id, true, utils.NonTransactional) + result, err := mig.dmOut.GetActions((*v1act)[0].Id, true, utils.NonTransactional) if err != nil { t.Error("Error when getting Actions ", err.Error()) } if !reflect.DeepEqual(*act, result) { t.Errorf("Expecting: %+v, received: %+v", *act, result) } + case dbtype == Move: + if err := mig.dmIN.SetActions((*v1act)[0].Id, *act, utils.NonTransactional); err != nil { + t.Error("Error when setting ActionPlan ", err.Error()) + } + currentVersion := engine.CurrentDataDBVersions() + err := mig.dmOut.DataDB().SetVersions(currentVersion, false) + if err != nil { + t.Error("Error when setting version for stats ", err.Error()) + } + err, _ = mig.Migrate([]string{utils.MetaActions}) + if err != nil { + t.Error("Error when migrating ActionPlans ", err.Error()) + } + result, err := mig.dmOut.GetActions((*v1act)[0].Id, true, utils.NonTransactional) + if err != nil { + t.Error("Error when getting ActionPlan ", err.Error()) + } + if !reflect.DeepEqual(*act, result) { + t.Errorf("Expecting: %+v, received: %+v", *act, result) + } } } @@ -442,11 +682,16 @@ func testMigratorSharedGroups(t *testing.T) { if err != nil { t.Error("Error when setting v1 SharedGroup ", err.Error()) } + currentVersion := engine.Versions{utils.StatS: 2, utils.Thresholds: 2, utils.Accounts: 2, utils.Actions: 2, utils.ActionTriggers: 2, utils.ActionPlans: 2, utils.SharedGroups: 1} + err = mig.dmOut.DataDB().SetVersions(currentVersion, false) + if err != nil { + t.Error("Error when setting version for stats ", err.Error()) + } err, _ = mig.Migrate([]string{utils.MetaSharedGroups}) if err != nil { t.Error("Error when migrating SharedGroup ", err.Error()) } - result, err := mig.dm.GetSharedGroup(v1sqp.Id, true, utils.NonTransactional) + result, err := mig.dmOut.GetSharedGroup(v1sqp.Id, true, utils.NonTransactional) if err != nil { t.Error("Error when getting SharedGroup ", err.Error()) } @@ -458,18 +703,42 @@ func testMigratorSharedGroups(t *testing.T) { if err != nil { t.Error("Error when setting v1 SharedGroup ", err.Error()) } + currentVersion := engine.Versions{utils.StatS: 2, utils.Thresholds: 2, utils.Accounts: 2, utils.Actions: 2, utils.ActionTriggers: 2, utils.ActionPlans: 2, utils.SharedGroups: 1} + err = mig.dmOut.DataDB().SetVersions(currentVersion, false) + if err != nil { + t.Error("Error when setting version for stats ", err.Error()) + } err, _ = mig.Migrate([]string{utils.MetaSharedGroups}) if err != nil { t.Error("Error when migrating SharedGroup ", err.Error()) } - result, err := mig.dm.GetSharedGroup(v1sqp.Id, true, utils.NonTransactional) + result, err := mig.dmOut.GetSharedGroup(v1sqp.Id, true, utils.NonTransactional) + if err != nil { + t.Error("Error when getting SharedGroup ", err.Error()) + } + if !reflect.DeepEqual(sqp, result) { + t.Errorf("Expecting: %+v, received: %+v", sqp, result) + } + case dbtype == Move: + if err := mig.dmIN.SetSharedGroup(sqp, utils.NonTransactional); err != nil { + t.Error("Error when setting SharedGroup ", err.Error()) + } + currentVersion := engine.CurrentDataDBVersions() + err := mig.dmOut.DataDB().SetVersions(currentVersion, false) + if err != nil { + t.Error("Error when setting version for stats ", err.Error()) + } + err, _ = mig.Migrate([]string{utils.MetaSharedGroups}) + if err != nil { + t.Error("Error when migrating SharedGroup ", err.Error()) + } + result, err := mig.dmOut.GetSharedGroup(sqp.Id, true, utils.NonTransactional) if err != nil { t.Error("Error when getting SharedGroup ", err.Error()) } if !reflect.DeepEqual(sqp, result) { t.Errorf("Expecting: %+v, received: %+v", sqp, result) } - } } @@ -557,13 +826,12 @@ func testMigratorStats(t *testing.T) { } switch { case dbtype == utils.REDIS: - err := mig.oldDataDB.setV1Stats(v1Sts) if err != nil { t.Error("Error when setting v1Stat ", err.Error()) } - currentVersion := engine.Versions{utils.StatS: 1, utils.Thresholds: 1, utils.Accounts: 2, utils.Actions: 2, utils.ActionTriggers: 2, utils.ActionPlans: 2, utils.SharedGroups: 2} - err = mig.dm.DataDB().SetVersions(currentVersion, false) + currentVersion := engine.Versions{utils.StatS: 1, utils.Thresholds: 2, utils.Accounts: 2, utils.Actions: 2, utils.ActionTriggers: 2, utils.ActionPlans: 2, utils.SharedGroups: 2} + err = mig.dmOut.DataDB().SetVersions(currentVersion, false) if err != nil { t.Error("Error when setting version for stats ", err.Error()) } @@ -571,68 +839,7 @@ func testMigratorStats(t *testing.T) { if err != nil { t.Error("Error when migrating Stats ", err.Error()) } - - result, err := mig.dm.GetStatQueueProfile("cgrates.org", v1Sts.Id, true, utils.NonTransactional) - if err != nil { - t.Error("Error when getting Stats ", err.Error()) - } - - if !reflect.DeepEqual(sqp.Tenant, result.Tenant) { - t.Errorf("Expecting: %+v, received: %+v", sqp.Tenant, result.Tenant) - } - if !reflect.DeepEqual(sqp.ID, result.ID) { - t.Errorf("Expecting: %+v, received: %+v", sqp.ID, result.ID) - } - if !reflect.DeepEqual(sqp.FilterIDs, result.FilterIDs) { - t.Errorf("Expecting: %+v, received: %+v", sqp.FilterIDs, result.FilterIDs) - } - if !reflect.DeepEqual(sqp.QueueLength, result.QueueLength) { - t.Errorf("Expecting: %+v, received: %+v", sqp.QueueLength, result.QueueLength) - } - if !reflect.DeepEqual(sqp.TTL, result.TTL) { - t.Errorf("Expecting: %+v, received: %+v", sqp.TTL, result.TTL) - } - if !reflect.DeepEqual(sqp.Metrics, result.Metrics) { - t.Errorf("Expecting: %+v, received: %+v", sqp.Metrics, result.Metrics) - } - if !reflect.DeepEqual(sqp.Thresholds, result.Thresholds) { - t.Errorf("Expecting: %+v, received: %+v", sqp.Thresholds, result.Thresholds) - } - if !reflect.DeepEqual(sqp.Blocker, result.Blocker) { - t.Errorf("Expecting: %+v, received: %+v", sqp.Blocker, result.Blocker) - } - if !reflect.DeepEqual(sqp.Stored, result.Stored) { - t.Errorf("Expecting: %+v, received: %+v", sqp.Stored, result.Stored) - } - if !reflect.DeepEqual(sqp.Weight, result.Weight) { - t.Errorf("Expecting: %+v, received: %+v", sqp.Weight, result.Weight) - } - if !reflect.DeepEqual(sqp, result) { - t.Errorf("Expecting: %+v, received: %+v", sqp, result) - } - result1, err := mig.dm.GetFilter("cgrates.org", v1Sts.Id, true, utils.NonTransactional) - if err != nil { - t.Error("Error when getting Stats ", err.Error()) - } - if !reflect.DeepEqual(filter, result1) { - t.Errorf("Expecting: %+v, received: %+v", filter, result1) - } - - case dbtype == utils.MONGO: - err := mig.oldDataDB.setV1Stats(v1Sts) - if err != nil { - t.Error("Error when setting v1Stat ", err.Error()) - } - currentVersion := engine.Versions{utils.StatS: 1, utils.Accounts: 2, utils.Actions: 2, utils.ActionTriggers: 2, utils.ActionPlans: 2, utils.SharedGroups: 2} - err = mig.dm.DataDB().SetVersions(currentVersion, false) - if err != nil { - t.Error("Error when setting version for stats ", err.Error()) - } - err, _ = mig.Migrate([]string{utils.MetaStats}) - if err != nil { - t.Error("Error when migrating Stats ", err.Error()) - } - result, err := mig.dm.GetStatQueueProfile("cgrates.org", v1Sts.Id, true, utils.NonTransactional) + result, err := mig.dmOut.GetStatQueueProfile("cgrates.org", v1Sts.Id, true, utils.NonTransactional) if err != nil { t.Error("Error when getting Stats ", err.Error()) } @@ -669,7 +876,7 @@ func testMigratorStats(t *testing.T) { if !reflect.DeepEqual(sqp, result) { t.Errorf("Expecting: %+v, received: %+v", sqp, result) } - result1, err := mig.dm.GetFilter("cgrates.org", v1Sts.Id, true, utils.NonTransactional) + result1, err := mig.dmOut.GetFilter("cgrates.org", v1Sts.Id, true, utils.NonTransactional) if err != nil { t.Error("Error when getting Stats ", err.Error()) } @@ -679,11 +886,158 @@ func testMigratorStats(t *testing.T) { if !reflect.DeepEqual(filter.Tenant, result1.Tenant) { t.Errorf("Expecting: %+v, received: %+v", filter.Tenant, result1.Tenant) } - } - result1, err := mig.dm.GetStatQueue("cgrates.org", v1Sts.Id, true, utils.NonTransactional) - if err != nil { - t.Error("Error when getting Stats ", err.Error()) - } - log.Print("Wrong version", result1) + result2, err := mig.dmOut.GetStatQueue("cgrates.org", sq.ID, true, utils.NonTransactional) + if err != nil { + t.Error("Error when getting Stats ", err.Error()) + } + if !reflect.DeepEqual(sq.ID, result2.ID) { + t.Errorf("Expecting: %+v, received: %+v", sq.ID, result2.ID) + } + case dbtype == utils.MONGO: + err := mig.oldDataDB.setV1Stats(v1Sts) + if err != nil { + t.Error("Error when setting v1Stat ", err.Error()) + } + currentVersion := engine.Versions{utils.StatS: 1, utils.Thresholds: 2, utils.Accounts: 2, utils.Actions: 2, utils.ActionTriggers: 2, utils.ActionPlans: 2, utils.SharedGroups: 2} + err = mig.dmOut.DataDB().SetVersions(currentVersion, false) + if err != nil { + t.Error("Error when setting version for stats ", err.Error()) + } + err, _ = mig.Migrate([]string{utils.MetaStats}) + if err != nil { + t.Error("Error when migrating Stats ", err.Error()) + } + result, err := mig.dmOut.GetStatQueueProfile("cgrates.org", v1Sts.Id, true, utils.NonTransactional) + if err != nil { + t.Error("Error when getting Stats ", err.Error()) + } + if !reflect.DeepEqual(sqp.Tenant, result.Tenant) { + t.Errorf("Expecting: %+v, received: %+v", sqp.Tenant, result.Tenant) + } + if !reflect.DeepEqual(sqp.ID, result.ID) { + t.Errorf("Expecting: %+v, received: %+v", sqp.ID, result.ID) + } + if !reflect.DeepEqual(sqp.FilterIDs, result.FilterIDs) { + t.Errorf("Expecting: %+v, received: %+v", sqp.FilterIDs, result.FilterIDs) + } + if !reflect.DeepEqual(sqp.QueueLength, result.QueueLength) { + t.Errorf("Expecting: %+v, received: %+v", sqp.QueueLength, result.QueueLength) + } + if !reflect.DeepEqual(sqp.TTL, result.TTL) { + t.Errorf("Expecting: %+v, received: %+v", sqp.TTL, result.TTL) + } + if !reflect.DeepEqual(sqp.Metrics, result.Metrics) { + t.Errorf("Expecting: %+v, received: %+v", sqp.Metrics, result.Metrics) + } + if !reflect.DeepEqual(sqp.Thresholds, result.Thresholds) { + t.Errorf("Expecting: %+v, received: %+v", sqp.Thresholds, result.Thresholds) + } + if !reflect.DeepEqual(sqp.Blocker, result.Blocker) { + t.Errorf("Expecting: %+v, received: %+v", sqp.Blocker, result.Blocker) + } + if !reflect.DeepEqual(sqp.Stored, result.Stored) { + t.Errorf("Expecting: %+v, received: %+v", sqp.Stored, result.Stored) + } + if !reflect.DeepEqual(sqp.Weight, result.Weight) { + t.Errorf("Expecting: %+v, received: %+v", sqp.Weight, result.Weight) + } + if !reflect.DeepEqual(sqp, result) { + t.Errorf("Expecting: %+v, received: %+v", sqp, result) + } + result1, err := mig.dmOut.GetFilter("cgrates.org", v1Sts.Id, true, utils.NonTransactional) + if err != nil { + t.Error("Error when getting Stats ", err.Error()) + } + if !reflect.DeepEqual(filter.ActivationInterval, result1.ActivationInterval) { + t.Errorf("Expecting: %+v, received: %+v", filter.ActivationInterval, result1.ActivationInterval) + } + if !reflect.DeepEqual(filter.Tenant, result1.Tenant) { + t.Errorf("Expecting: %+v, received: %+v", filter.Tenant, result1.Tenant) + } + result2, err := mig.dmOut.GetStatQueue("cgrates.org", sq.ID, true, utils.NonTransactional) + if err != nil { + t.Error("Error when getting Stats ", err.Error()) + } + if !reflect.DeepEqual(sq.ID, result2.ID) { + t.Errorf("Expecting: %+v, received: %+v", sq.ID, result2.ID) + } + case dbtype == Move: + if err := mig.dmIN.SetStatQueueProfile(sqp); err != nil { + t.Error("Error when setting Stats ", err.Error()) + } + if err := mig.dmIN.SetStatQueue(sq); err != nil { + t.Error("Error when setting Stats ", err.Error()) + } + currentVersion := engine.CurrentDataDBVersions() + err := mig.dmOut.DataDB().SetVersions(currentVersion, false) + if err != nil { + t.Error("Error when setting version for stats ", err.Error()) + } + err, _ = mig.Migrate([]string{utils.MetaStats}) + if err != nil { + t.Error("Error when migrating Stats ", err.Error()) + } + result, err := mig.dmOut.GetStatQueueProfile(sqp.Tenant, sqp.ID, true, utils.NonTransactional) + if err != nil { + t.Error("Error when getting Stats ", err.Error()) + } + result1, err := mig.dmOut.GetStatQueue(sq.Tenant, sq.ID, true, utils.NonTransactional) + if err != nil { + t.Error("Error when getting Stats ", err.Error()) + } + if !reflect.DeepEqual(sqp, result) { + t.Errorf("Expecting: %+v, received: %+v", sqp, result) + } + if !reflect.DeepEqual(sq.ID, result1.ID) { + t.Errorf("Expecting: %+v, received: %+v", sq.ID, result1.ID) + } + } +} + +func testMigratorTPRatingProfile(t *testing.T) { + tpRatingProfile := &utils.TPRatingProfile{ + TPid: "TPRProf1", + LoadId: "RPrf", + Direction: "*out", + Tenant: "Tenant1", + Category: "Category", + Subject: "Subject", + RatingPlanActivations: []*utils.TPRatingActivation{ + &utils.TPRatingActivation{ + ActivationTime: "2014-07-29T15:00:00Z", + RatingPlanId: "PlanOne", + FallbackSubjects: "FallBack", + CdrStatQueueIds: "RandomId", + }, + &utils.TPRatingActivation{ + ActivationTime: "2015-07-29T10:00:00Z", + RatingPlanId: "PlanTwo", + FallbackSubjects: "FallOut", + CdrStatQueueIds: "RandomIdTwo", + }, + }, + } + switch dbtype { + case Move: + if err := mig.InStorDB().SetTPRatingProfiles([]*utils.TPRatingProfile{tpRatingProfile}); err != nil { + t.Error("Error when setting Stats ", err.Error()) + } + currentVersion := engine.CurrentDataDBVersions() + err := mig.dmOut.DataDB().SetVersions(currentVersion, false) + if err != nil { + t.Error("Error when setting version for stats ", err.Error()) + } + err, _ = mig.Migrate([]string{utils.MetaTpRatingProfiles}) + if err != nil { + t.Error("Error when migrating Stats ", err.Error()) + } + result, err := mig.OutStorDB().GetTPRatingProfiles(tpRatingProfile) + if err != nil { + t.Error("Error when getting Stats ", err.Error()) + } + if !reflect.DeepEqual(tpRatingProfile, result[0]) { + t.Errorf("Expecting: %+v, received: %+v", tpRatingProfile, result[0]) + } + } } diff --git a/migrator/rating_plan.go b/migrator/rating_plan.go new file mode 100644 index 000000000..9f0b316fb --- /dev/null +++ b/migrator/rating_plan.go @@ -0,0 +1,78 @@ +/* +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" + "strings" + + "github.com/cgrates/cgrates/engine" + "github.com/cgrates/cgrates/utils" +) + +func (m *Migrator) migrateCurrentRatingPlans() (err error) { + var ids []string + ids, err = m.dmIN.DataDB().GetKeysForPrefix(utils.RATING_PLAN_PREFIX) + if err != nil { + return err + } + for _, id := range ids { + idg := strings.TrimPrefix(id, utils.RATING_PLAN_PREFIX) + rp, err := m.dmIN.GetRatingPlan(idg, true, utils.NonTransactional) + if err != nil { + return err + } + if rp != nil { + if m.dryRun != true { + if err := m.dmOut.SetRatingPlan(rp, utils.NonTransactional); err != nil { + return err + } + } + } + } + return +} + +func (m *Migrator) migrateRatingPlans() (err error) { + var vrs engine.Versions + current := engine.CurrentDataDBVersions() + vrs, err = m.dmOut.DataDB().GetVersions(utils.TBLVersions) + if err != nil { + return utils.NewCGRError(utils.Migrator, + utils.ServerErrorCaps, + err.Error(), + fmt.Sprintf("error: <%s> when querying oldDataDB for versions", err.Error())) + } else if len(vrs) == 0 { + return utils.NewCGRError(utils.Migrator, + utils.MandatoryIEMissingCaps, + utils.UndefinedVersion, + "version number is not defined for ActionTriggers model") + } + switch vrs[utils.RatingPlan] { + case current[utils.RatingPlan]: + if m.sameDBname { + return + } + if err := m.migrateCurrentRatingPlans(); err != nil { + return err + } + return + } + return +} diff --git a/migrator/rating_profile.go b/migrator/rating_profile.go new file mode 100644 index 000000000..7801f7178 --- /dev/null +++ b/migrator/rating_profile.go @@ -0,0 +1,78 @@ +/* +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" + "strings" + + "github.com/cgrates/cgrates/engine" + "github.com/cgrates/cgrates/utils" +) + +func (m *Migrator) migrateCurrentRatingProfiles() (err error) { + var ids []string + ids, err = m.dmIN.DataDB().GetKeysForPrefix(utils.RATING_PROFILE_PREFIX) + if err != nil { + return err + } + for _, id := range ids { + idg := strings.TrimPrefix(id, utils.RATING_PROFILE_PREFIX) + rp, err := m.dmIN.GetRatingProfile(idg, true, utils.NonTransactional) + if err != nil { + return err + } + if rp != nil { + if m.dryRun != true { + if err := m.dmOut.SetRatingProfile(rp, utils.NonTransactional); err != nil { + return err + } + } + } + } + return +} + +func (m *Migrator) migrateRatingProfiles() (err error) { + var vrs engine.Versions + current := engine.CurrentDataDBVersions() + vrs, err = m.dmOut.DataDB().GetVersions(utils.TBLVersions) + if err != nil { + return utils.NewCGRError(utils.Migrator, + utils.ServerErrorCaps, + err.Error(), + fmt.Sprintf("error: <%s> when querying oldDataDB for versions", err.Error())) + } else if len(vrs) == 0 { + return utils.NewCGRError(utils.Migrator, + utils.MandatoryIEMissingCaps, + utils.UndefinedVersion, + "version number is not defined for ActionTriggers model") + } + switch vrs[utils.RatingProfile] { + case current[utils.RatingProfile]: + if m.sameDBname { + return + } + if err := m.migrateCurrentRatingProfiles(); err != nil { + return err + } + return + } + return +} diff --git a/migrator/request_filter.go b/migrator/request_filter.go new file mode 100644 index 000000000..c0cda1e89 --- /dev/null +++ b/migrator/request_filter.go @@ -0,0 +1,78 @@ +/* +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" + "strings" + + "github.com/cgrates/cgrates/engine" + "github.com/cgrates/cgrates/utils" +) + +func (m *Migrator) migrateCurrentRequestFilter() (err error) { + var ids []string + ids, err = m.dmIN.DataDB().GetKeysForPrefix("request_filter_indexes") + if err != nil { + return err + } + for _, id := range ids { + idg := strings.TrimPrefix(id, "request_filter_indexes") + rq, err := m.dmIN.GetReqFilterIndexes(idg) + if err != nil { + return err + } + if rq != nil { + if m.dryRun != true { + if err := m.dmOut.SetReqFilterIndexes(id, rq); err != nil { + return err + } + } + } + } + return +} + +func (m *Migrator) migrateRequestFilter() (err error) { + var vrs engine.Versions + current := engine.CurrentDataDBVersions() + vrs, err = m.dmOut.DataDB().GetVersions(utils.TBLVersions) + if err != nil { + return utils.NewCGRError(utils.Migrator, + utils.ServerErrorCaps, + err.Error(), + fmt.Sprintf("error: <%s> when querying oldDataDB for versions", err.Error())) + } else if len(vrs) == 0 { + return utils.NewCGRError(utils.Migrator, + utils.MandatoryIEMissingCaps, + utils.UndefinedVersion, + "version number is not defined for ActionTriggers model") + } + switch vrs[utils.RQF] { + case current[utils.RQF]: + if m.sameDBname { + return + } + if err := m.migrateCurrentRequestFilter(); err != nil { + return err + } + return + } + return +} diff --git a/migrator/resource.go b/migrator/resource.go new file mode 100644 index 000000000..f55f78484 --- /dev/null +++ b/migrator/resource.go @@ -0,0 +1,80 @@ +/* +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" + "strings" + + "github.com/cgrates/cgrates/config" + "github.com/cgrates/cgrates/engine" + "github.com/cgrates/cgrates/utils" +) + +func (m *Migrator) migrateCurrentResource() (err error) { + var ids []string + tenant := config.CgrConfig().DefaultTenant + ids, err = m.dmIN.DataDB().GetKeysForPrefix(utils.ResourceProfilesPrefix) + if err != nil { + return err + } + for _, id := range ids { + idg := strings.TrimPrefix(id, utils.ResourceProfilesPrefix) + res, err := m.dmIN.GetResource(tenant, idg, true, utils.NonTransactional) + if err != nil { + return err + } + if res != nil { + if m.dryRun != true { + if err := m.dmOut.SetResource(res); err != nil { + return err + } + } + } + } + return +} + +func (m *Migrator) migrateResources() (err error) { + var vrs engine.Versions + current := engine.CurrentDataDBVersions() + vrs, err = m.dmOut.DataDB().GetVersions(utils.TBLVersions) + if err != nil { + return utils.NewCGRError(utils.Migrator, + utils.ServerErrorCaps, + err.Error(), + fmt.Sprintf("error: <%s> when querying oldDataDB for versions", err.Error())) + } else if len(vrs) == 0 { + return utils.NewCGRError(utils.Migrator, + utils.MandatoryIEMissingCaps, + utils.UndefinedVersion, + "version number is not defined for ActionTriggers model") + } + switch vrs[utils.Resource] { + case current[utils.Resource]: + if m.sameDBname { + return + } + if err := m.migrateCurrentResource(); err != nil { + return err + } + return + } + return +} diff --git a/migrator/sharedgroup.go b/migrator/sharedgroup.go index 8976052d8..47de6cddf 100644 --- a/migrator/sharedgroup.go +++ b/migrator/sharedgroup.go @@ -20,6 +20,7 @@ package migrator import ( "fmt" + "strings" "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/utils" @@ -31,7 +32,30 @@ type v1SharedGroup struct { MemberIds []string } -func (m *Migrator) migrateSharedGroups() (err error) { +func (m *Migrator) migrateCurrentSharedGroups() (err error) { + var ids []string + ids, err = m.dmIN.DataDB().GetKeysForPrefix(utils.SHARED_GROUP_PREFIX) + if err != nil { + return err + } + for _, id := range ids { + idg := strings.TrimPrefix(id, utils.SHARED_GROUP_PREFIX) + sgs, err := m.dmIN.GetSharedGroup(idg, true, utils.NonTransactional) + if err != nil { + return err + } + if sgs != nil { + if m.dryRun != true { + if err := m.dmOut.SetSharedGroup(sgs, utils.NonTransactional); err != nil { + return err + } + } + } + } + return +} + +func (m *Migrator) migrateV1SharedGroups() (err error) { var v1SG *v1SharedGroup for { v1SG, err = m.oldDataDB.getV1SharedGroup() @@ -44,7 +68,7 @@ func (m *Migrator) migrateSharedGroups() (err error) { if v1SG != nil { acnt := v1SG.AsSharedGroup() if m.dryRun != true { - if err = m.dm.SetSharedGroup(acnt, utils.NonTransactional); err != nil { + if err = m.dmOut.SetSharedGroup(acnt, utils.NonTransactional); err != nil { return err } m.stats[utils.SharedGroups] += 1 @@ -53,7 +77,7 @@ func (m *Migrator) migrateSharedGroups() (err error) { } // All done, update version wtih current one vrs := engine.Versions{utils.SharedGroups: engine.CurrentStorDBVersions()[utils.SharedGroups]} - if err = m.dm.DataDB().SetVersions(vrs, false); err != nil { + if err = m.dmOut.DataDB().SetVersions(vrs, false); err != nil { return utils.NewCGRError(utils.Migrator, utils.ServerErrorCaps, err.Error(), @@ -62,6 +86,39 @@ func (m *Migrator) migrateSharedGroups() (err error) { return } +func (m *Migrator) migrateSharedGroups() (err error) { + var vrs engine.Versions + current := engine.CurrentDataDBVersions() + vrs, err = m.dmOut.DataDB().GetVersions(utils.TBLVersions) + if err != nil { + return utils.NewCGRError(utils.Migrator, + utils.ServerErrorCaps, + err.Error(), + fmt.Sprintf("error: <%s> when querying oldDataDB for versions", err.Error())) + } else if len(vrs) == 0 { + return utils.NewCGRError(utils.Migrator, + utils.MandatoryIEMissingCaps, + utils.UndefinedVersion, + "version number is not defined for ActionTriggers model") + } + switch vrs[utils.SharedGroups] { + case current[utils.SharedGroups]: + if m.sameDBname { + return + } + if err := m.migrateCurrentSharedGroups(); err != nil { + return err + } + return + + case 1: + if err := m.migrateV1SharedGroups(); err != nil { + return err + } + } + return +} + func (v1SG v1SharedGroup) AsSharedGroup() (sg *engine.SharedGroup) { sg = &engine.SharedGroup{ Id: v1SG.Id, diff --git a/migrator/stats.go b/migrator/stats.go index aad3c4e86..304e3c4f8 100644 --- a/migrator/stats.go +++ b/migrator/stats.go @@ -20,7 +20,6 @@ package migrator import ( "fmt" - "log" "strconv" "strings" "time" @@ -60,30 +59,52 @@ type v1Stat struct { type v1Stats []*v1Stat -func (m *Migrator) migrateStats() (err error) { - var vrs engine.Versions - if m.dm.DataDB() == nil { - return utils.NewCGRError(utils.Migrator, - utils.MandatoryIEMissingCaps, - utils.NoStorDBConnection, - "no connection to datadb") - } - vrs, err = m.dm.DataDB().GetVersions(utils.TBLVersions) +func (m *Migrator) migrateCurrentStats() (err error) { + var ids []string + tenant := config.CgrConfig().DefaultTenant + //StatQueue + ids, err = m.dmIN.DataDB().GetKeysForPrefix(utils.StatQueuePrefix) if err != nil { - return utils.NewCGRError(utils.Migrator, - utils.ServerErrorCaps, - err.Error(), - fmt.Sprintf("error: <%s> when querying oldDataDB for versions", err.Error())) - } else if len(vrs) == 0 { - return utils.NewCGRError(utils.Migrator, - utils.MandatoryIEMissingCaps, - utils.UndefinedVersion, - "version number is not defined for Stats model") + return err } - if vrs[utils.StatS] != 1 { // Right now we only support migrating from version 1 - log.Print("Wrong version") - return + for _, id := range ids { + idg := strings.TrimPrefix(id, utils.StatQueuePrefix+tenant+":") + sgs, err := m.dmIN.GetStatQueue(tenant, idg, true, utils.NonTransactional) + if err != nil { + return err + } + if sgs != nil { + if m.dryRun != true { + if err := m.dmOut.SetStatQueue(sgs); err != nil { + return err + } + } + } } + //StatQueueProfile + ids, err = m.dmIN.DataDB().GetKeysForPrefix(utils.StatQueueProfilePrefix) + if err != nil { + return err + } + for _, id := range ids { + idg := strings.TrimPrefix(id, utils.StatQueueProfilePrefix+tenant+":") + sgs, err := m.dmIN.GetStatQueueProfile(tenant, idg, true, utils.NonTransactional) + if err != nil { + return err + } + if sgs != nil { + if m.dryRun != true { + if err := m.dmOut.SetStatQueueProfile(sgs); err != nil { + return err + } + } + } + } + + return +} + +func (m *Migrator) migrateV1CDRSTATS() (err error) { var v1Sts *v1Stat for { v1Sts, err = m.oldDataDB.getV1Stats() @@ -106,14 +127,14 @@ func (m *Migrator) migrateStats() (err error) { if err != nil { return err } - if m.dryRun != true { - if err := m.dm.SetFilter(filter); err != nil { + if !m.dryRun { + if err := m.dmOut.SetFilter(filter); err != nil { return err } - if err := m.dm.SetStatQueue(sq); err != nil { + if err := m.dmOut.SetStatQueue(sq); err != nil { return err } - if err := m.dm.SetStatQueueProfile(sts); err != nil { + if err := m.dmOut.SetStatQueueProfile(sts); err != nil { return err } m.stats[utils.StatS] += 1 @@ -123,7 +144,7 @@ func (m *Migrator) migrateStats() (err error) { if m.dryRun != true { // All done, update version wtih current one vrs := engine.Versions{utils.StatS: engine.CurrentStorDBVersions()[utils.StatS]} - if err = m.dm.DataDB().SetVersions(vrs, false); err != nil { + if err = m.dmOut.DataDB().SetVersions(vrs, false); err != nil { return utils.NewCGRError(utils.Migrator, utils.ServerErrorCaps, err.Error(), @@ -133,6 +154,39 @@ func (m *Migrator) migrateStats() (err error) { return } +func (m *Migrator) migrateStats() (err error) { + var vrs engine.Versions + current := engine.CurrentDataDBVersions() + vrs, err = m.dmOut.DataDB().GetVersions(utils.TBLVersions) + if err != nil { + return utils.NewCGRError(utils.Migrator, + utils.ServerErrorCaps, + err.Error(), + fmt.Sprintf("error: <%s> when querying oldDataDB for versions", err.Error())) + } else if len(vrs) == 0 { + return utils.NewCGRError(utils.Migrator, + utils.MandatoryIEMissingCaps, + utils.UndefinedVersion, + "version number is not defined for ActionTriggers model") + } + switch vrs[utils.StatS] { + case current[utils.StatS]: + if m.sameDBname { + return + } + if err := m.migrateCurrentStats(); err != nil { + return err + } + return + + case 1: + if err := m.migrateV1CDRSTATS(); err != nil { + return err + } + } + return +} + func (v1Sts v1Stat) AsStatQP() (filter *engine.Filter, sq *engine.StatQueue, stq *engine.StatQueueProfile, err error) { var filters []*engine.RequestFilter if len(v1Sts.SetupInterval) == 1 { diff --git a/migrator/subscribers.go b/migrator/subscribers.go new file mode 100644 index 000000000..2a4e62ff7 --- /dev/null +++ b/migrator/subscribers.go @@ -0,0 +1,71 @@ +/* +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) migrateCurrentSubscribers() (err error) { + subs, err := m.dmIN.GetSubscribers() + if err != nil { + return err + } + for id, sub := range subs { + if sub != nil { + if m.dryRun != true { + if err := m.dmOut.SetSubscriber(id, sub); err != nil { + return err + } + } + } + } + return +} + +func (m *Migrator) migrateSubscribers() (err error) { + var vrs engine.Versions + current := engine.CurrentDataDBVersions() + vrs, err = m.dmOut.DataDB().GetVersions(utils.TBLVersions) + if err != nil { + return utils.NewCGRError(utils.Migrator, + utils.ServerErrorCaps, + err.Error(), + fmt.Sprintf("error: <%s> when querying oldDataDB for versions", err.Error())) + } else if len(vrs) == 0 { + return utils.NewCGRError(utils.Migrator, + utils.MandatoryIEMissingCaps, + utils.UndefinedVersion, + "version number is not defined for ActionTriggers model") + } + switch vrs[utils.Subscribers] { + case current[utils.Subscribers]: + if m.sameDBname { + return + } + if err := m.migrateCurrentSubscribers(); err != nil { + return err + } + return + } + return +} diff --git a/migrator/thresholds.go b/migrator/thresholds.go index d7be759c3..486f29296 100644 --- a/migrator/thresholds.go +++ b/migrator/thresholds.go @@ -20,7 +20,7 @@ package migrator import ( "fmt" - "log" + "strings" "time" "github.com/cgrates/cgrates/config" @@ -29,16 +29,14 @@ import ( ) type v2ActionTrigger struct { - ID string // original csv tag - UniqueID string // individual id - ThresholdType string //*min_event_counter, *max_event_counter, *min_balance_counter, *max_balance_counter, *min_balance, *max_balance, *balance_expired - // stats: *min_asr, *max_asr, *min_acd, *max_acd, *min_tcd, *max_tcd, *min_acc, *max_acc, *min_tcc, *max_tcc, *min_ddc, *max_ddc - ThresholdValue float64 - Recurrent bool // reset excuted flag each run - MinSleep time.Duration // Minimum duration between two executions in case of recurrent triggers - ExpirationDate time.Time - ActivationDate time.Time - //BalanceType string // *monetary/*voice etc + ID string // original csv tag + UniqueID string // individual id + ThresholdType string //*min_event_counter, *max_event_counter, *min_balance_counter, *max_balance_counter, *min_balance, *max_balance, *balance_expired + ThresholdValue float64 + Recurrent bool // reset excuted flag each run + MinSleep time.Duration // Minimum duration between two executions in case of recurrent triggers + ExpirationDate time.Time + ActivationDate time.Time Balance *engine.BalanceFilter //filtru Weight float64 ActionsID string @@ -49,30 +47,51 @@ type v2ActionTrigger struct { type v2ActionTriggers []*v2ActionTrigger -func (m *Migrator) migratev1ActionTriggers() (err error) { - var vrs engine.Versions - if m.dm.DataDB() == nil { - return utils.NewCGRError(utils.Migrator, - utils.MandatoryIEMissingCaps, - utils.NoStorDBConnection, - "no connection to datadb") - } - vrs, err = m.dm.DataDB().GetVersions(utils.TBLVersions) +func (m *Migrator) migrateCurrentThresholds() (err error) { + var ids []string + tenant := config.CgrConfig().DefaultTenant + //StatQueue + ids, err = m.dmIN.DataDB().GetKeysForPrefix(utils.ThresholdPrefix) if err != nil { - return utils.NewCGRError(utils.Migrator, - utils.ServerErrorCaps, - err.Error(), - fmt.Sprintf("error: <%s> when querying oldDataDB for versions", err.Error())) - } else if len(vrs) == 0 { - return utils.NewCGRError(utils.Migrator, - utils.MandatoryIEMissingCaps, - utils.UndefinedVersion, - "version number is not defined for Stats model") + return err } - if vrs[utils.Thresholds] != 1 { // Right now we only support migrating from version 1 - log.Print("Wrong version") - return + for _, id := range ids { + idg := strings.TrimPrefix(id, utils.ThresholdPrefix+tenant+":") + ths, err := m.dmIN.GetThreshold(tenant, idg, true, utils.NonTransactional) + if err != nil { + return err + } + if ths != nil { + if m.dryRun != true { + if err := m.dmOut.SetThreshold(ths); err != nil { + return err + } + } + } } + //StatQueueProfile + ids, err = m.dmIN.DataDB().GetKeysForPrefix(utils.ThresholdProfilePrefix) + if err != nil { + return err + } + for _, id := range ids { + idg := strings.TrimPrefix(id, utils.ThresholdProfilePrefix+tenant+":") + ths, err := m.dmIN.GetThresholdProfile(tenant, idg, true, utils.NonTransactional) + if err != nil { + return err + } + if ths != nil { + if m.dryRun != true { + if err := m.dmOut.SetThresholdProfile(ths); err != nil { + return err + } + } + } + } + return +} + +func (m *Migrator) migrateV2ActionTriggers() (err error) { var v2ACT *v2ActionTrigger for { v2ACT, err = m.oldDataDB.getV2ActionTrigger() @@ -88,13 +107,13 @@ func (m *Migrator) migratev1ActionTriggers() (err error) { return err } if m.dryRun != true { - if err := m.dm.SetFilter(filter); err != nil { + if err := m.dmOut.SetFilter(filter); err != nil { return err } - if err := m.dm.SetThreshold(th); err != nil { + if err := m.dmOut.SetThreshold(th); err != nil { return err } - if err := m.dm.SetThresholdProfile(thp); err != nil { + if err := m.dmOut.SetThresholdProfile(thp); err != nil { return err } m.stats[utils.Thresholds] += 1 @@ -104,7 +123,7 @@ func (m *Migrator) migratev1ActionTriggers() (err error) { if m.dryRun != true { // All done, update version wtih current one vrs := engine.Versions{utils.Thresholds: engine.CurrentStorDBVersions()[utils.Thresholds]} - if err = m.dm.DataDB().SetVersions(vrs, false); err != nil { + if err = m.dmOut.DataDB().SetVersions(vrs, false); err != nil { return utils.NewCGRError(utils.Migrator, utils.ServerErrorCaps, err.Error(), @@ -113,6 +132,39 @@ func (m *Migrator) migratev1ActionTriggers() (err error) { } return } + +func (m *Migrator) migrateThresholds() (err error) { + var vrs engine.Versions + current := engine.CurrentDataDBVersions() + vrs, err = m.dmOut.DataDB().GetVersions(utils.TBLVersions) + if err != nil { + return utils.NewCGRError(utils.Migrator, + utils.ServerErrorCaps, + err.Error(), + fmt.Sprintf("error: <%s> when querying oldDataDB for versions", err.Error())) + } else if len(vrs) == 0 { + return utils.NewCGRError(utils.Migrator, + utils.MandatoryIEMissingCaps, + utils.UndefinedVersion, + "version number is not defined for ActionTriggers model") + } + switch vrs[utils.Thresholds] { + case current[utils.Thresholds]: + if m.sameDBname { + return + } + if err := m.migrateCurrentThresholds(); err != nil { + return err + } + return + + case 1: + if err := m.migrateV2ActionTriggers(); err != nil { + return err + } + } + return +} func (v2ATR v2ActionTrigger) AsThreshold() (thp *engine.ThresholdProfile, th *engine.Threshold, filter *engine.Filter, err error) { var filters []*engine.RequestFilter if *v2ATR.Balance.ID != "" { @@ -194,7 +246,7 @@ func (v2ATR v2ActionTrigger) AsThreshold() (thp *engine.ThresholdProfile, th *en func (m *Migrator) SasThreshold(v2ATR *engine.ActionTrigger) (err error) { var vrs engine.Versions - if m.dm.DataDB() == nil { + if m.dmOut.DataDB() == nil { return utils.NewCGRError(utils.Migrator, utils.MandatoryIEMissingCaps, utils.NoStorDBConnection, @@ -206,21 +258,21 @@ func (m *Migrator) SasThreshold(v2ATR *engine.ActionTrigger) (err error) { return err } if filter != nil { - if err := m.dm.SetFilter(filter); err != nil { + if err := m.dmOut.SetFilter(filter); err != nil { return err } } - if err := m.dm.SetThreshold(th); err != nil { + if err := m.dmOut.SetThreshold(th); err != nil { return err } - if err := m.dm.SetThresholdProfile(thp); err != nil { + if err := m.dmOut.SetThresholdProfile(thp); err != nil { return err } m.stats[utils.Thresholds] += 1 } // All done, update version wtih current one vrs = engine.Versions{utils.Thresholds: engine.CurrentStorDBVersions()[utils.Thresholds]} - if err = m.dm.DataDB().SetVersions(vrs, false); err != nil { + if err = m.dmOut.DataDB().SetVersions(vrs, false); err != nil { return utils.NewCGRError(utils.Migrator, utils.ServerErrorCaps, err.Error(), diff --git a/migrator/timings.go b/migrator/timings.go new file mode 100644 index 000000000..0bdc6e9b1 --- /dev/null +++ b/migrator/timings.go @@ -0,0 +1,78 @@ +/* +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" + "strings" + + "github.com/cgrates/cgrates/engine" + "github.com/cgrates/cgrates/utils" +) + +func (m *Migrator) migrateCurrentTiming() (err error) { + var ids []string + ids, err = m.dmIN.DataDB().GetKeysForPrefix(utils.TimingsPrefix) + if err != nil { + return err + } + for _, id := range ids { + idg := strings.TrimPrefix(id, utils.TimingsPrefix) + tm, err := m.dmIN.GetTiming(idg, true, utils.NonTransactional) + if err != nil { + return err + } + if tm != nil { + if m.dryRun != true { + if err := m.dmOut.SetTiming(tm); err != nil { + return err + } + } + } + } + return +} + +func (m *Migrator) migrateTimings() (err error) { + var vrs engine.Versions + current := engine.CurrentDataDBVersions() + vrs, err = m.dmOut.DataDB().GetVersions(utils.TBLVersions) + if err != nil { + return utils.NewCGRError(utils.Migrator, + utils.ServerErrorCaps, + err.Error(), + fmt.Sprintf("error: <%s> when querying oldDataDB for versions", err.Error())) + } else if len(vrs) == 0 { + return utils.NewCGRError(utils.Migrator, + utils.MandatoryIEMissingCaps, + utils.UndefinedVersion, + "version number is not defined for ActionTriggers model") + } + switch vrs[utils.Timing] { + case current[utils.Timing]: + if m.sameDBname { + return + } + if err := m.migrateCurrentTiming(); err != nil { + return err + } + return + } + return +} diff --git a/migrator/tp_account_actions.go b/migrator/tp_account_actions.go new file mode 100644 index 000000000..a3de0e86b --- /dev/null +++ b/migrator/tp_account_actions.go @@ -0,0 +1,76 @@ +/* +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) migrateCurrentTPaccountacction() (err error) { + tpids, err := m.InStorDB().GetTpIds(utils.TBLTPActionTriggers) + if err != nil { + return err + } + + for _, tpid := range tpids { + dest, err := m.InStorDB().GetTPAccountActions(&utils.TPAccountActions{TPid: tpid}) + if err != nil { + return err + } + if dest != nil { + if m.dryRun != true { + if err := m.OutStorDB().SetTPAccountActions(dest); err != nil { + return err + } + } + } + } + return +} + +func (m *Migrator) migrateTPaccountacction() (err error) { + var vrs engine.Versions + current := engine.CurrentDataDBVersions() + vrs, err = m.dmOut.DataDB().GetVersions(utils.TBLVersions) + if err != nil { + return utils.NewCGRError(utils.Migrator, + utils.ServerErrorCaps, + err.Error(), + fmt.Sprintf("error: <%s> when querying oldDataDB for versions", err.Error())) + } else if len(vrs) == 0 { + return utils.NewCGRError(utils.Migrator, + utils.MandatoryIEMissingCaps, + utils.UndefinedVersion, + "version number is not defined for ActionTriggers model") + } + switch vrs[utils.TpAccountActions] { + case current[utils.TpAccountActions]: + if m.sameDBname { + return + } + if err := m.migrateCurrentTPaccountacction(); err != nil { + return err + } + return + } + return +} diff --git a/migrator/tp_action_plans.go b/migrator/tp_action_plans.go new file mode 100644 index 000000000..5441d2e37 --- /dev/null +++ b/migrator/tp_action_plans.go @@ -0,0 +1,83 @@ +/* +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) migrateCurrentTPactionplans() (err error) { + tpids, err := m.InStorDB().GetTpIds(utils.TBLTPActionPlans) + if err != nil { + return err + } + + for _, tpid := range tpids { + ids, err := m.InStorDB().GetTpTableIds(tpid, utils.TBLTPActionPlans, utils.TPDistinctIds{}, map[string]string{}, nil) + if err != nil { + return err + } + for _, id := range ids { + + dest, err := m.InStorDB().GetTPActionPlans(tpid, id) + if err != nil { + return err + } + if dest != nil { + if m.dryRun != true { + if err := m.OutStorDB().SetTPActionPlans(dest); err != nil { + return err + } + } + } + } + } + return +} + +func (m *Migrator) migrateTPactionplans() (err error) { + var vrs engine.Versions + current := engine.CurrentDataDBVersions() + vrs, err = m.dmOut.DataDB().GetVersions(utils.TBLVersions) + if err != nil { + return utils.NewCGRError(utils.Migrator, + utils.ServerErrorCaps, + err.Error(), + fmt.Sprintf("error: <%s> when querying oldDataDB for versions", err.Error())) + } else if len(vrs) == 0 { + return utils.NewCGRError(utils.Migrator, + utils.MandatoryIEMissingCaps, + utils.UndefinedVersion, + "version number is not defined for ActionTriggers model") + } + switch vrs[utils.TpActionPlans] { + case current[utils.TpActionPlans]: + if m.sameDBname { + return + } + if err := m.migrateCurrentTPactionplans(); err != nil { + return err + } + return + } + return +} diff --git a/migrator/tp_action_triggers.go b/migrator/tp_action_triggers.go new file mode 100644 index 000000000..cb83bd6cc --- /dev/null +++ b/migrator/tp_action_triggers.go @@ -0,0 +1,83 @@ +/* +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) migrateCurrentTPactiontriggers() (err error) { + tpids, err := m.InStorDB().GetTpIds(utils.TBLTPActionTriggers) + if err != nil { + return err + } + + for _, tpid := range tpids { + ids, err := m.InStorDB().GetTpTableIds(tpid, utils.TBLTPActionTriggers, utils.TPDistinctIds{}, map[string]string{}, nil) + if err != nil { + return err + } + for _, id := range ids { + + dest, err := m.InStorDB().GetTPActionTriggers(tpid, id) + if err != nil { + return err + } + if dest != nil { + if m.dryRun != true { + if err := m.OutStorDB().SetTPActionTriggers(dest); err != nil { + return err + } + } + } + } + } + return +} + +func (m *Migrator) migrateTPactiontriggers() (err error) { + var vrs engine.Versions + current := engine.CurrentDataDBVersions() + vrs, err = m.dmOut.DataDB().GetVersions(utils.TBLVersions) + if err != nil { + return utils.NewCGRError(utils.Migrator, + utils.ServerErrorCaps, + err.Error(), + fmt.Sprintf("error: <%s> when querying oldDataDB for versions", err.Error())) + } else if len(vrs) == 0 { + return utils.NewCGRError(utils.Migrator, + utils.MandatoryIEMissingCaps, + utils.UndefinedVersion, + "version number is not defined for ActionTriggers model") + } + switch vrs[utils.TpActionTriggers] { + case current[utils.TpActionTriggers]: + if m.sameDBname { + return + } + if err := m.migrateCurrentTPactiontriggers(); err != nil { + return err + } + return + } + return +} diff --git a/migrator/tp_actions.go b/migrator/tp_actions.go new file mode 100644 index 000000000..d5c81d946 --- /dev/null +++ b/migrator/tp_actions.go @@ -0,0 +1,83 @@ +/* +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) migrateCurrentTPactions() (err error) { + tpids, err := m.InStorDB().GetTpIds(utils.TBLTPActions) + if err != nil { + return err + } + + for _, tpid := range tpids { + ids, err := m.InStorDB().GetTpTableIds(tpid, utils.TBLTPActions, utils.TPDistinctIds{}, map[string]string{}, nil) + if err != nil { + return err + } + for _, id := range ids { + + dest, err := m.InStorDB().GetTPActions(tpid, id) + if err != nil { + return err + } + if dest != nil { + if m.dryRun != true { + if err := m.OutStorDB().SetTPActions(dest); err != nil { + return err + } + } + } + } + } + return +} + +func (m *Migrator) migrateTPactions() (err error) { + var vrs engine.Versions + current := engine.CurrentDataDBVersions() + vrs, err = m.dmOut.DataDB().GetVersions(utils.TBLVersions) + if err != nil { + return utils.NewCGRError(utils.Migrator, + utils.ServerErrorCaps, + err.Error(), + fmt.Sprintf("error: <%s> when querying oldDataDB for versions", err.Error())) + } else if len(vrs) == 0 { + return utils.NewCGRError(utils.Migrator, + utils.MandatoryIEMissingCaps, + utils.UndefinedVersion, + "version number is not defined for ActionTriggers model") + } + switch vrs[utils.TpActions] { + case current[utils.TpActions]: + if m.sameDBname { + return + } + if err := m.migrateCurrentTPactions(); err != nil { + return err + } + return + } + return +} diff --git a/migrator/tp_aliases.go b/migrator/tp_aliases.go new file mode 100644 index 000000000..aabdb251c --- /dev/null +++ b/migrator/tp_aliases.go @@ -0,0 +1,77 @@ +/* +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) migrateCurrentTPaliases() (err error) { + tpids, err := m.InStorDB().GetTpIds(utils.TBLTPAliases) + if err != nil { + return err + } + + for _, tpid := range tpids { + dest, err := m.InStorDB().GetTPAliases(&utils.TPAliases{TPid: tpid}) + if err != nil { + return err + } + if dest != nil { + if m.dryRun != true { + if err := m.OutStorDB().SetTPAliases(dest); err != nil { + return err + } + } + } + } + + return +} + +func (m *Migrator) migrateTPaliases() (err error) { + var vrs engine.Versions + current := engine.CurrentDataDBVersions() + vrs, err = m.dmOut.DataDB().GetVersions(utils.TBLVersions) + if err != nil { + return utils.NewCGRError(utils.Migrator, + utils.ServerErrorCaps, + err.Error(), + fmt.Sprintf("error: <%s> when querying oldDataDB for versions", err.Error())) + } else if len(vrs) == 0 { + return utils.NewCGRError(utils.Migrator, + utils.MandatoryIEMissingCaps, + utils.UndefinedVersion, + "version number is not defined for ActionTriggers model") + } + switch vrs[utils.TpAliases] { + case current[utils.TpAliases]: + if m.sameDBname { + return + } + if err := m.migrateCurrentTPaliases(); err != nil { + return err + } + return + } + return +} diff --git a/migrator/tp_cdr_stats.go b/migrator/tp_cdr_stats.go new file mode 100644 index 000000000..21ee5edb1 --- /dev/null +++ b/migrator/tp_cdr_stats.go @@ -0,0 +1,83 @@ +/* +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) migrateCurrentTPcdrstats() (err error) { + tpids, err := m.InStorDB().GetTpIds(utils.TBLTPCdrStats) + if err != nil { + return err + } + + for _, tpid := range tpids { + ids, err := m.InStorDB().GetTpTableIds(tpid, utils.TBLTPCdrStats, utils.TPDistinctIds{}, map[string]string{}, nil) + if err != nil { + return err + } + for _, id := range ids { + + dest, err := m.InStorDB().GetTPCdrStats(tpid, id) + if err != nil { + return err + } + if dest != nil { + if m.dryRun != true { + if err := m.OutStorDB().SetTPCdrStats(dest); err != nil { + return err + } + } + } + } + } + return +} + +func (m *Migrator) migrateTPcdrstats() (err error) { + var vrs engine.Versions + current := engine.CurrentDataDBVersions() + vrs, err = m.dmOut.DataDB().GetVersions(utils.TBLVersions) + if err != nil { + return utils.NewCGRError(utils.Migrator, + utils.ServerErrorCaps, + err.Error(), + fmt.Sprintf("error: <%s> when querying oldDataDB for versions", err.Error())) + } else if len(vrs) == 0 { + return utils.NewCGRError(utils.Migrator, + utils.MandatoryIEMissingCaps, + utils.UndefinedVersion, + "version number is not defined for ActionTriggers model") + } + switch vrs[utils.TpCdrStats] { + case current[utils.TpCdrStats]: + if m.sameDBname { + return + } + if err := m.migrateCurrentTPcdrstats(); err != nil { + return err + } + return + } + return +} diff --git a/migrator/tp_derived_chargers.go b/migrator/tp_derived_chargers.go new file mode 100644 index 000000000..3619bf93c --- /dev/null +++ b/migrator/tp_derived_chargers.go @@ -0,0 +1,78 @@ +/* +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) migrateCurrentTPderivedchargers() (err error) { + tpids, err := m.InStorDB().GetTpIds(utils.TBLTPDerivedChargers) + if err != nil { + return err + } + + for _, tpid := range tpids { + + dest, err := m.InStorDB().GetTPDerivedChargers(&utils.TPDerivedChargers{TPid: tpid}) + if err != nil { + return err + } + if dest != nil { + if m.dryRun != true { + + if err := m.OutStorDB().SetTPDerivedChargers(dest); err != nil { + return err + } + } + } + } + return +} + +func (m *Migrator) migrateTPderivedchargers() (err error) { + var vrs engine.Versions + current := engine.CurrentDataDBVersions() + vrs, err = m.dmOut.DataDB().GetVersions(utils.TBLVersions) + if err != nil { + return utils.NewCGRError(utils.Migrator, + utils.ServerErrorCaps, + err.Error(), + fmt.Sprintf("error: <%s> when querying oldDataDB for versions", err.Error())) + } else if len(vrs) == 0 { + return utils.NewCGRError(utils.Migrator, + utils.MandatoryIEMissingCaps, + utils.UndefinedVersion, + "version number is not defined for ActionTriggers model") + } + switch vrs[utils.TpDerivedCharges] { + case current[utils.TpDerivedCharges]: + if m.sameDBname { + return + } + if err := m.migrateCurrentTPderivedchargers(); err != nil { + return err + } + return + } + return +} diff --git a/migrator/tp_destination_rates.go b/migrator/tp_destination_rates.go new file mode 100644 index 000000000..3a243e06b --- /dev/null +++ b/migrator/tp_destination_rates.go @@ -0,0 +1,82 @@ +/* +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) migrateCurrentTPdestinationrates() (err error) { + tpids, err := m.InStorDB().GetTpIds(utils.TBLTPRatingPlans) + if err != nil { + return err + } + + for _, tpid := range tpids { + ids, err := m.InStorDB().GetTpTableIds(tpid, utils.TBLTPRatingPlans, utils.TPDistinctIds{}, map[string]string{}, nil) + if err != nil { + return err + } + for _, id := range ids { + dest, err := m.InStorDB().GetTPDestinationRates(tpid, id, nil) + if err != nil { + return err + } + if dest != nil { + if m.dryRun != true { + if err := m.OutStorDB().SetTPDestinationRates(dest); err != nil { + return err + } + } + } + } + } + return +} + +func (m *Migrator) migrateTPdestinationrates() (err error) { + var vrs engine.Versions + current := engine.CurrentDataDBVersions() + vrs, err = m.dmOut.DataDB().GetVersions(utils.TBLVersions) + if err != nil { + return utils.NewCGRError(utils.Migrator, + utils.ServerErrorCaps, + err.Error(), + fmt.Sprintf("error: <%s> when querying oldDataDB for versions", err.Error())) + } else if len(vrs) == 0 { + return utils.NewCGRError(utils.Migrator, + utils.MandatoryIEMissingCaps, + utils.UndefinedVersion, + "version number is not defined for ActionTriggers model") + } + switch vrs[utils.TpDestinationRates] { + case current[utils.TpDestinationRates]: + if m.sameDBname { + return + } + if err := m.migrateCurrentTPdestinationrates(); err != nil { + return err + } + return + } + return +} diff --git a/migrator/tp_destinations.go b/migrator/tp_destinations.go new file mode 100644 index 000000000..4f070d1a0 --- /dev/null +++ b/migrator/tp_destinations.go @@ -0,0 +1,82 @@ +/* +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) migrateCurrentTPDestinations() (err error) { + tpids, err := m.InStorDB().GetTpIds(utils.TBLTPDestinations) + if err != nil { + return err + } + + for _, tpid := range tpids { + ids, err := m.InStorDB().GetTpTableIds(tpid, utils.TBLTPDestinations, utils.TPDistinctIds{}, map[string]string{}, nil) + if err != nil { + return err + } + for _, id := range ids { + dest, err := m.InStorDB().GetTPDestinations(tpid, id) + if err != nil { + return err + } + if dest != nil { + if m.dryRun != true { + if err := m.OutStorDB().SetTPDestinations(dest); err != nil { + return err + } + } + } + } + } + return +} + +func (m *Migrator) migrateTPDestinations() (err error) { + var vrs engine.Versions + current := engine.CurrentDataDBVersions() + vrs, err = m.dmOut.DataDB().GetVersions(utils.TBLVersions) + if err != nil { + return utils.NewCGRError(utils.Migrator, + utils.ServerErrorCaps, + err.Error(), + fmt.Sprintf("error: <%s> when querying oldDataDB for versions", err.Error())) + } else if len(vrs) == 0 { + return utils.NewCGRError(utils.Migrator, + utils.MandatoryIEMissingCaps, + utils.UndefinedVersion, + "version number is not defined for ActionTriggers model") + } + switch vrs[utils.TpDestinations] { + case current[utils.TpDestinations]: + if m.sameDBname { + return + } + if err := m.migrateCurrentTPDestinations(); err != nil { + return err + } + return + } + return +} diff --git a/migrator/tp_filters.go b/migrator/tp_filters.go new file mode 100644 index 000000000..ff718a454 --- /dev/null +++ b/migrator/tp_filters.go @@ -0,0 +1,82 @@ +/* +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) migrateCurrentTPfilters() (err error) { + tpids, err := m.InStorDB().GetTpIds(utils.TBLTPFilters) + if err != nil { + return err + } + + for _, tpid := range tpids { + ids, err := m.InStorDB().GetTpTableIds(tpid, utils.TBLTPFilters, utils.TPDistinctIds{}, map[string]string{}, nil) + if err != nil { + return err + } + for _, id := range ids { + dest, err := m.InStorDB().GetTPFilters(tpid, id) + if err != nil { + return err + } + if dest != nil { + if m.dryRun != true { + if err := m.OutStorDB().SetTPFilters(dest); err != nil { + return err + } + } + } + } + } + return +} + +func (m *Migrator) migrateTPfilters() (err error) { + var vrs engine.Versions + current := engine.CurrentDataDBVersions() + vrs, err = m.dmOut.DataDB().GetVersions(utils.TBLVersions) + if err != nil { + return utils.NewCGRError(utils.Migrator, + utils.ServerErrorCaps, + err.Error(), + fmt.Sprintf("error: <%s> when querying oldDataDB for versions", err.Error())) + } else if len(vrs) == 0 { + return utils.NewCGRError(utils.Migrator, + utils.MandatoryIEMissingCaps, + utils.UndefinedVersion, + "version number is not defined for ActionTriggers model") + } + switch vrs[utils.TpFilters] { + case current[utils.TpFilters]: + if m.sameDBname { + return + } + if err := m.migrateCurrentTPfilters(); err != nil { + return err + } + return + } + return +} diff --git a/migrator/tp_lcrs.go b/migrator/tp_lcrs.go new file mode 100644 index 000000000..7ab8b0d89 --- /dev/null +++ b/migrator/tp_lcrs.go @@ -0,0 +1,76 @@ +/* +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) migrateCurrentTPlcrs() (err error) { + tpids, err := m.InStorDB().GetTpIds(utils.TBLTPLcrs) + if err != nil { + return err + } + + for _, tpid := range tpids { + dest, err := m.InStorDB().GetTPLCRs(&utils.TPLcrRules{TPid: tpid}) + if err != nil { + return err + } + if dest != nil { + if m.dryRun != true { + if err := m.OutStorDB().SetTPLCRs(dest); err != nil { + return err + } + } + } + } + return +} + +func (m *Migrator) migrateTPlcrs() (err error) { + var vrs engine.Versions + current := engine.CurrentDataDBVersions() + vrs, err = m.dmOut.DataDB().GetVersions(utils.TBLVersions) + if err != nil { + return utils.NewCGRError(utils.Migrator, + utils.ServerErrorCaps, + err.Error(), + fmt.Sprintf("error: <%s> when querying oldDataDB for versions", err.Error())) + } else if len(vrs) == 0 { + return utils.NewCGRError(utils.Migrator, + utils.MandatoryIEMissingCaps, + utils.UndefinedVersion, + "version number is not defined for ActionTriggers model") + } + switch vrs[utils.TpLcrs] { + case current[utils.TpLcrs]: + if m.sameDBname { + return + } + if err := m.migrateCurrentTPcdrstats(); err != nil { + return err + } + return + } + return +} diff --git a/migrator/tp_rates.go b/migrator/tp_rates.go new file mode 100644 index 000000000..682a77ea7 --- /dev/null +++ b/migrator/tp_rates.go @@ -0,0 +1,83 @@ +/* +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) migrateCurrentTPrates() (err error) { + tpids, err := m.InStorDB().GetTpIds(utils.TBLTPDestinations) + if err != nil { + return err + } + + for _, tpid := range tpids { + ids, err := m.InStorDB().GetTpTableIds(tpid, utils.TBLTPDestinations, utils.TPDistinctIds{}, map[string]string{}, nil) + if err != nil { + return err + } + for _, id := range ids { + + dest, err := m.InStorDB().GetTPRates(tpid, id) + if err != nil { + return err + } + if dest != nil { + if m.dryRun != true { + if err := m.OutStorDB().SetTPRates(dest); err != nil { + return err + } + } + } + } + } + return +} + +func (m *Migrator) migrateTPrates() (err error) { + var vrs engine.Versions + current := engine.CurrentDataDBVersions() + vrs, err = m.dmOut.DataDB().GetVersions(utils.TBLVersions) + if err != nil { + return utils.NewCGRError(utils.Migrator, + utils.ServerErrorCaps, + err.Error(), + fmt.Sprintf("error: <%s> when querying oldDataDB for versions", err.Error())) + } else if len(vrs) == 0 { + return utils.NewCGRError(utils.Migrator, + utils.MandatoryIEMissingCaps, + utils.UndefinedVersion, + "version number is not defined for ActionTriggers model") + } + switch vrs[utils.TpRates] { + case current[utils.TpRates]: + if m.sameDBname { + return + } + if err := m.migrateCurrentTPrates(); err != nil { + return err + } + return + } + return +} diff --git a/migrator/tp_rating_plans.go b/migrator/tp_rating_plans.go new file mode 100644 index 000000000..1ade51e22 --- /dev/null +++ b/migrator/tp_rating_plans.go @@ -0,0 +1,83 @@ +/* +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) migrateCurrentTPratingplans() (err error) { + tpids, err := m.InStorDB().GetTpIds(utils.TBLTPRatingPlans) + if err != nil { + return err + } + + for _, tpid := range tpids { + ids, err := m.InStorDB().GetTpTableIds(tpid, utils.TBLTPRatingPlans, utils.TPDistinctIds{}, map[string]string{}, nil) + if err != nil { + return err + } + for _, id := range ids { + + rps, err := m.InStorDB().GetTPRatingPlans(tpid, id, nil) + if err != nil { + return err + } + if rps != nil { + if m.dryRun != true { + if err := m.InStorDB().SetTPRatingPlans(rps); err != nil { + return err + } + } + } + } + } + return +} + +func (m *Migrator) migrateTPratingplans() (err error) { + var vrs engine.Versions + current := engine.CurrentDataDBVersions() + vrs, err = m.dmOut.DataDB().GetVersions(utils.TBLVersions) + if err != nil { + return utils.NewCGRError(utils.Migrator, + utils.ServerErrorCaps, + err.Error(), + fmt.Sprintf("error: <%s> when querying oldDataDB for versions", err.Error())) + } else if len(vrs) == 0 { + return utils.NewCGRError(utils.Migrator, + utils.MandatoryIEMissingCaps, + utils.UndefinedVersion, + "version number is not defined for ActionTriggers model") + } + switch vrs[utils.TpRatingPlans] { + case current[utils.TpRatingPlans]: + if m.sameDBname { + return + } + if err := m.migrateCurrentTPratingplans(); err != nil { + return err + } + return + } + return +} diff --git a/migrator/tp_rating_profiles.go b/migrator/tp_rating_profiles.go new file mode 100644 index 000000000..45620492b --- /dev/null +++ b/migrator/tp_rating_profiles.go @@ -0,0 +1,77 @@ +/* +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) migrateCurrentTPratingprofiles() (err error) { + + tpids, err := m.InStorDB().GetTpIds(utils.TBLTPRateProfiles) + if err != nil { + return err + } + + for _, tpid := range tpids { + dest, err := m.InStorDB().GetTPRatingProfiles(&utils.TPRatingProfile{TPid: tpid}) + if err != nil { + return err + } + if dest != nil { + if m.dryRun != true { + if err := m.OutStorDB().SetTPRatingProfiles(dest); err != nil { + return err + } + } + } + } + return +} + +func (m *Migrator) migrateTPratingprofiles() (err error) { + var vrs engine.Versions + current := engine.CurrentDataDBVersions() + vrs, err = m.dmOut.DataDB().GetVersions(utils.TBLVersions) + if err != nil { + return utils.NewCGRError(utils.Migrator, + utils.ServerErrorCaps, + err.Error(), + fmt.Sprintf("error: <%s> when querying oldDataDB for versions", err.Error())) + } else if len(vrs) == 0 { + return utils.NewCGRError(utils.Migrator, + utils.MandatoryIEMissingCaps, + utils.UndefinedVersion, + "version number is not defined for ActionTriggers model") + } + switch vrs[utils.TpRatingProfiles] { + case current[utils.TpRatingProfiles]: + if m.sameDBname { + return + } + if err := m.migrateCurrentTPratingprofiles(); err != nil { + return err + } + return + } + return +} diff --git a/migrator/tp_resources.go b/migrator/tp_resources.go new file mode 100644 index 000000000..e72bae174 --- /dev/null +++ b/migrator/tp_resources.go @@ -0,0 +1,83 @@ +/* +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) migrateCurrentTPresources() (err error) { + tpids, err := m.InStorDB().GetTpIds(utils.TBLTPResources) + if err != nil { + return err + } + + for _, tpid := range tpids { + ids, err := m.InStorDB().GetTpTableIds(tpid, utils.TBLTPResources, utils.TPDistinctIds{}, map[string]string{}, nil) + if err != nil { + return err + } + for _, id := range ids { + + dest, err := m.InStorDB().GetTPResources(tpid, id) + if err != nil { + return err + } + if dest != nil { + if m.dryRun != true { + if err := m.OutStorDB().SetTPResources(dest); err != nil { + return err + } + } + } + } + } + return +} + +func (m *Migrator) migrateTPresources() (err error) { + var vrs engine.Versions + current := engine.CurrentDataDBVersions() + vrs, err = m.dmOut.DataDB().GetVersions(utils.TBLVersions) + if err != nil { + return utils.NewCGRError(utils.Migrator, + utils.ServerErrorCaps, + err.Error(), + fmt.Sprintf("error: <%s> when querying oldDataDB for versions", err.Error())) + } else if len(vrs) == 0 { + return utils.NewCGRError(utils.Migrator, + utils.MandatoryIEMissingCaps, + utils.UndefinedVersion, + "version number is not defined for ActionTriggers model") + } + switch vrs[utils.TpResources] { + case current[utils.TpResources]: + if m.sameDBname { + return + } + if err := m.migrateCurrentTPresources(); err != nil { + return err + } + return + } + return +} diff --git a/migrator/tp_shared_groups.go b/migrator/tp_shared_groups.go new file mode 100644 index 000000000..779a72557 --- /dev/null +++ b/migrator/tp_shared_groups.go @@ -0,0 +1,83 @@ +/* +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) migrateCurrentTPsharedgroups() (err error) { + tpids, err := m.InStorDB().GetTpIds(utils.TBLTPSharedGroups) + if err != nil { + return err + } + + for _, tpid := range tpids { + ids, err := m.InStorDB().GetTpTableIds(tpid, utils.TBLTPSharedGroups, utils.TPDistinctIds{}, map[string]string{}, nil) + if err != nil { + return err + } + for _, id := range ids { + + dest, err := m.InStorDB().GetTPSharedGroups(tpid, id) + if err != nil { + return err + } + if dest != nil { + if m.dryRun != true { + if err := m.OutStorDB().SetTPSharedGroups(dest); err != nil { + return err + } + } + } + } + } + return +} + +func (m *Migrator) migrateTPsharedgroups() (err error) { + var vrs engine.Versions + current := engine.CurrentDataDBVersions() + vrs, err = m.dmOut.DataDB().GetVersions(utils.TBLVersions) + if err != nil { + return utils.NewCGRError(utils.Migrator, + utils.ServerErrorCaps, + err.Error(), + fmt.Sprintf("error: <%s> when querying oldDataDB for versions", err.Error())) + } else if len(vrs) == 0 { + return utils.NewCGRError(utils.Migrator, + utils.MandatoryIEMissingCaps, + utils.UndefinedVersion, + "version number is not defined for ActionTriggers model") + } + switch vrs[utils.TpSharedGroups] { + case current[utils.TpSharedGroups]: + if m.sameDBname { + return + } + if err := m.migrateCurrentTPsharedgroups(); err != nil { + return err + } + return + } + return +} diff --git a/migrator/tp_stats.go b/migrator/tp_stats.go new file mode 100644 index 000000000..7e7d4d605 --- /dev/null +++ b/migrator/tp_stats.go @@ -0,0 +1,83 @@ +/* +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) migrateCurrentTPstats() (err error) { + tpids, err := m.InStorDB().GetTpIds(utils.TBLTPStats) + if err != nil { + return err + } + + for _, tpid := range tpids { + ids, err := m.InStorDB().GetTpTableIds(tpid, utils.TBLTPStats, utils.TPDistinctIds{}, map[string]string{}, nil) + if err != nil { + return err + } + for _, id := range ids { + + dest, err := m.InStorDB().GetTPStats(tpid, id) + if err != nil { + return err + } + if dest != nil { + if m.dryRun != true { + if err := m.OutStorDB().SetTPStats(dest); err != nil { + return err + } + } + } + } + } + return +} + +func (m *Migrator) migrateTPstats() (err error) { + var vrs engine.Versions + current := engine.CurrentDataDBVersions() + vrs, err = m.dmOut.DataDB().GetVersions(utils.TBLVersions) + if err != nil { + return utils.NewCGRError(utils.Migrator, + utils.ServerErrorCaps, + err.Error(), + fmt.Sprintf("error: <%s> when querying oldDataDB for versions", err.Error())) + } else if len(vrs) == 0 { + return utils.NewCGRError(utils.Migrator, + utils.MandatoryIEMissingCaps, + utils.UndefinedVersion, + "version number is not defined for ActionTriggers model") + } + switch vrs[utils.TpStats] { + case current[utils.TpStats]: + if m.sameDBname { + return + } + if err := m.migrateCurrentTPstats(); err != nil { + return err + } + return + } + return +} diff --git a/migrator/tp_thresholds.go b/migrator/tp_thresholds.go new file mode 100644 index 000000000..3e7be5750 --- /dev/null +++ b/migrator/tp_thresholds.go @@ -0,0 +1,83 @@ +/* +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) migrateCurrentTPthresholds() (err error) { + tpids, err := m.InStorDB().GetTpIds(utils.TBLTPThresholds) + if err != nil { + return err + } + + for _, tpid := range tpids { + ids, err := m.InStorDB().GetTpTableIds(tpid, utils.TBLTPThresholds, utils.TPDistinctIds{}, map[string]string{}, nil) + if err != nil { + return err + } + for _, id := range ids { + + dest, err := m.InStorDB().GetTPThresholds(tpid, id) + if err != nil { + return err + } + if dest != nil { + if m.dryRun != true { + if err := m.OutStorDB().SetTPThresholds(dest); err != nil { + return err + } + } + } + } + } + return +} + +func (m *Migrator) migrateTPthresholds() (err error) { + var vrs engine.Versions + current := engine.CurrentDataDBVersions() + vrs, err = m.dmOut.DataDB().GetVersions(utils.TBLVersions) + if err != nil { + return utils.NewCGRError(utils.Migrator, + utils.ServerErrorCaps, + err.Error(), + fmt.Sprintf("error: <%s> when querying oldDataDB for versions", err.Error())) + } else if len(vrs) == 0 { + return utils.NewCGRError(utils.Migrator, + utils.MandatoryIEMissingCaps, + utils.UndefinedVersion, + "version number is not defined for ActionTriggers model") + } + switch vrs[utils.TpThresholds] { + case current[utils.TpThresholds]: + if m.sameDBname { + return + } + if err := m.migrateCurrentTPthresholds(); err != nil { + return err + } + return + } + return +} diff --git a/migrator/tp_timings.go b/migrator/tp_timings.go new file mode 100644 index 000000000..30fb8d217 --- /dev/null +++ b/migrator/tp_timings.go @@ -0,0 +1,83 @@ +/* +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) migrateCurrentTPTiming() (err error) { + tpids, err := m.InStorDB().GetTpIds(utils.TBLTPTimings) + if err != nil { + return err + } + + for _, tpid := range tpids { + ids, err := m.InStorDB().GetTpTableIds(tpid, utils.TBLTPTimings, utils.TPDistinctIds{}, map[string]string{}, nil) + if err != nil { + return err + } + for _, id := range ids { + + tm, err := m.InStorDB().GetTPTimings(tpid, id) + if err != nil { + return err + } + if tm != nil { + if m.dryRun != true { + if err := m.OutStorDB().SetTPTimings(tm); err != nil { + return err + } + } + } + } + } + return +} + +func (m *Migrator) migrateTpTimings() (err error) { + var vrs engine.Versions + current := engine.CurrentDataDBVersions() + vrs, err = m.dmOut.DataDB().GetVersions(utils.TBLVersions) + if err != nil { + return utils.NewCGRError(utils.Migrator, + utils.ServerErrorCaps, + err.Error(), + fmt.Sprintf("error: <%s> when querying oldDataDB for versions", err.Error())) + } else if len(vrs) == 0 { + return utils.NewCGRError(utils.Migrator, + utils.MandatoryIEMissingCaps, + utils.UndefinedVersion, + "version number is not defined for ActionTriggers model") + } + switch vrs[utils.TpTiming] { + case current[utils.TpTiming]: + if m.sameDBname { + return + } + if err := m.migrateCurrentTPTiming(); err != nil { + return err + } + return + } + return +} diff --git a/migrator/tp_users.go b/migrator/tp_users.go new file mode 100644 index 000000000..0343a7dd3 --- /dev/null +++ b/migrator/tp_users.go @@ -0,0 +1,77 @@ +/* +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) migrateCurrentTPusers() (err error) { + tpids, err := m.InStorDB().GetTpIds(utils.TBLTPUsers) + if err != nil { + return err + } + + for _, tpid := range tpids { + dest, err := m.InStorDB().GetTPUsers(&utils.TPUsers{TPid: tpid}) + if err != nil { + return err + } + if dest != nil { + if m.dryRun != true { + if err := m.OutStorDB().SetTPUsers(dest); err != nil { + return err + } + } + } + + } + return +} + +func (m *Migrator) migrateTPusers() (err error) { + var vrs engine.Versions + current := engine.CurrentDataDBVersions() + vrs, err = m.dmOut.DataDB().GetVersions(utils.TBLVersions) + if err != nil { + return utils.NewCGRError(utils.Migrator, + utils.ServerErrorCaps, + err.Error(), + fmt.Sprintf("error: <%s> when querying oldDataDB for versions", err.Error())) + } else if len(vrs) == 0 { + return utils.NewCGRError(utils.Migrator, + utils.MandatoryIEMissingCaps, + utils.UndefinedVersion, + "version number is not defined for ActionTriggers model") + } + switch vrs[utils.TpUsers] { + case current[utils.TpUsers]: + if m.sameDBname { + return + } + if err := m.migrateCurrentTPusers(); err != nil { + return err + } + return + } + return +} diff --git a/migrator/user.go b/migrator/user.go new file mode 100644 index 000000000..6111b6fce --- /dev/null +++ b/migrator/user.go @@ -0,0 +1,78 @@ +/* +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" + "strings" + + "github.com/cgrates/cgrates/engine" + "github.com/cgrates/cgrates/utils" +) + +func (m *Migrator) migrateCurrentUser() (err error) { + var ids []string + ids, err = m.dmIN.DataDB().GetKeysForPrefix(utils.USERS_PREFIX) + if err != nil { + return err + } + for _, id := range ids { + idg := strings.TrimPrefix(id, utils.USERS_PREFIX) + usr, err := m.dmIN.GetUser(idg) + if err != nil { + return err + } + if usr != nil { + if m.dryRun != true { + if err := m.dmOut.SetUser(usr); err != nil { + return err + } + } + } + } + return +} + +func (m *Migrator) migrateUser() (err error) { + var vrs engine.Versions + current := engine.CurrentDataDBVersions() + vrs, err = m.dmOut.DataDB().GetVersions(utils.TBLVersions) + if err != nil { + return utils.NewCGRError(utils.Migrator, + utils.ServerErrorCaps, + err.Error(), + fmt.Sprintf("error: <%s> when querying oldDataDB for versions", err.Error())) + } else if len(vrs) == 0 { + return utils.NewCGRError(utils.Migrator, + utils.MandatoryIEMissingCaps, + utils.UndefinedVersion, + "version number is not defined for ActionTriggers model") + } + switch vrs[utils.User] { + case current[utils.User]: + if m.sameDBname { + return + } + if err := m.migrateCurrentUser(); err != nil { + return err + } + return + } + return +} diff --git a/migrator/v1migrator_utils.go b/migrator/v1migrator_utils.go index 3be1e723d..1c99be99e 100644 --- a/migrator/v1migrator_utils.go +++ b/migrator/v1migrator_utils.go @@ -23,11 +23,12 @@ import ( "fmt" "strconv" + "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/utils" ) -func ConfigureV1DataStorage(db_type, host, port, name, user, pass, marshaler string) (db V1DataDB, err error) { - var d V1DataDB +func ConfigureV1DataStorage(db_type, host, port, name, user, pass, marshaler string) (db MigratorDataDB, err error) { + var d MigratorDataDB switch db_type { case utils.REDIS: var db_nb int @@ -42,7 +43,7 @@ func ConfigureV1DataStorage(db_type, host, port, name, user, pass, marshaler str d, err = newv1RedisStorage(host, db_nb, pass, marshaler) case utils.MONGO: d, err = newv1MongoStorage(host, port, name, user, pass, utils.DataDB, nil) - db = d.(V1DataDB) + db = d.(MigratorDataDB) default: err = errors.New(fmt.Sprintf("Unknown db '%s' valid options are '%s' or '%s'", db_type, utils.REDIS, utils.MONGO)) @@ -52,3 +53,11 @@ func ConfigureV1DataStorage(db_type, host, port, name, user, pass, marshaler str } return d, nil } + +func (m *Migrator) InStorDB() engine.LoadStorage { + return m.oldStorDB.(engine.LoadStorage) +} + +func (m *Migrator) OutStorDB() engine.LoadStorage { + return m.storDB.(engine.LoadStorage) +} diff --git a/migrator/v1mongo_data.go b/migrator/v1mongo_data.go index ba0d7b26e..52472a0ba 100644 --- a/migrator/v1mongo_data.go +++ b/migrator/v1mongo_data.go @@ -61,7 +61,7 @@ func newv1MongoStorage(host, port, db, user, pass, storageType string, cdrsIndex v1ms = &v1Mongo{db: db, session: session, v1ms: engine.NewCodecMsgpackMarshaler()} return } - +func (v1ms *v1Mongo) Close() {} func (v1ms *v1Mongo) getKeysForPrefix(prefix string) ([]string, error) { return nil, nil } diff --git a/migrator/v1redis.go b/migrator/v1redis.go index d4764b226..7616cd6cf 100644 --- a/migrator/v1redis.go +++ b/migrator/v1redis.go @@ -22,6 +22,7 @@ import ( "fmt" "github.com/cgrates/cgrates/engine" + "github.com/cgrates/cgrates/guardian" "github.com/cgrates/cgrates/utils" "github.com/mediocregopher/radix.v2/pool" @@ -78,7 +79,7 @@ func (v1rs *v1Redis) cmd(cmd string, args ...interface{}) *redis.Resp { return redis.NewResp(err) } result := c1.Cmd(cmd, args...) - if result.IsType(redis.IOErr) { // Failover mecanism + if result.IsType(redis.IOErr) { // Failover mecaneism utils.Logger.Warning(fmt.Sprintf(" error <%s>, attempting failover.", result.Err.Error())) c2, err := v1rs.dbPool.Get() if err == nil { @@ -92,6 +93,7 @@ func (v1rs *v1Redis) cmd(cmd string, args ...interface{}) *redis.Resp { } return result } +func (v1rs *v1Redis) Close() {} func (v1rs *v1Redis) getKeysForPrefix(prefix string) ([]string, error) { r := v1rs.cmd("KEYS", prefix+"*") @@ -101,6 +103,32 @@ func (v1rs *v1Redis) getKeysForPrefix(prefix string) ([]string, error) { return r.List() } +// Adds a single load instance to load history +func (v1rs *v1Redis) AddLoadHistory(ldInst *utils.LoadInstance, loadHistSize int, transactionID string) error { + if loadHistSize == 0 { // Load history disabled + return nil + } + marshaled, err := v1rs.ms.Marshal(&ldInst) + if err != nil { + return err + } + _, err = guardian.Guardian.Guard(func() (interface{}, error) { // Make sure we do it locked since other instance can modify history while we read it + histLen, err := v1rs.cmd("LLEN", utils.LOADINST_KEY).Int() + if err != nil { + return nil, err + } + if histLen >= loadHistSize { // Have hit maximum history allowed, remove oldest element in order to add new one + if err := v1rs.cmd("RPOP", utils.LOADINST_KEY).Err; err != nil { + return nil, err + } + } + err = v1rs.cmd("LPUSH", utils.LOADINST_KEY, marshaled).Err + return nil, err + }, 0, utils.LOADINST_KEY) + + return err +} + //Account methods //get func (v1rs *v1Redis) getv1Account() (v1Acnt *v1Account, err error) { diff --git a/utils/consts.go b/utils/consts.go index ac8c9f21c..a90d707b3 100755 --- a/utils/consts.go +++ b/utils/consts.go @@ -392,19 +392,8 @@ const ( StoppedCaps = "STOPPED" SchedulerNotRunningCaps = "SCHEDULLER_NOT_RUNNING" MetaScheduler = "*scheduler" - MetaCostDetails = "*cost_details" - MetaAccounts = "*accounts" - MetaActionPlans = "*action_plans" - MetaActionTriggers = "*action_triggers" - MetaActions = "*actions" - MetaSharedGroups = "*shared_groups" - MetaStats = "*stats" - MetaThresholds = "*thresholds" - Migrator = "migrator" - UnsupportedMigrationTask = "unsupported migration task" NoStorDBConnection = "not connected to StorDB" UndefinedVersion = "undefined version" - MetaSetVersions = "*set_versions" UnsupportedDB = "unsupported database" ACCOUNT_SUMMARY = "AccountSummary" TxtSuffix = ".txt" @@ -429,13 +418,6 @@ const ( MetaEveryMinute = "*every_minute" MetaHourly = "*hourly" ID = "ID" - MetaASR = "*asr" - MetaACD = "*acd" - MetaTCD = "*tcd" - MetaACC = "*acc" - MetaTCC = "*tcc" - MetaPDD = "*pdd" - MetaDDC = "*ddc" CacheDestinations = "destinations" CacheReverseDestinations = "reverse_destinations" CacheRatingPlans = "rating_plans" @@ -491,13 +473,123 @@ const ( Disabled = "Disabled" Action = "Action" ThresholdSv1ProcessEvent = "ThresholdSv1.ProcessEvent" - MetaNow = "*now" SMGenericV2UpdateSession = "SMGenericV2.UpdateSession" SMGenericV2InitiateSession = "SMGenericV2.InitiateSession" SMGenericV1UpdateSession = "SMGenericV1.UpdateSession" SMGenericV1InitiateSession = "SMGenericV1.InitiateSession" ) +//Meta +const ( + MetaASR = "*asr" + MetaACD = "*acd" + MetaTCD = "*tcd" + MetaACC = "*acc" + MetaTCC = "*tcc" + MetaPDD = "*pdd" + MetaDDC = "*ddc" + MetaNow = "*now" +) + +//Migrator Metas +const ( + MetaSetVersions = "*set_versions" + MetaCostDetails = "*cost_details" + MetaAccounts = "*accounts" + MetaActionPlans = "*action_plans" + MetaActionTriggers = "*action_triggers" + MetaActions = "*actions" + MetaSharedGroups = "*shared_groups" + MetaStats = "*stats" + MetaThresholds = "*thresholds" + MetaRatingPlans = "*ratingplans" + MetaRatingProfile = "*ratingprofile" + MetaDestinations = "*destinations" + MetaReverseDestinations = "*reversedestinations" + MetaLCR = "*lcr" + MetaCdrStats = "*cdrstats" + MetaTiming = "*Timing" + MetaRQF = "*RQF" + MetaResource = "*Resource" + MetaReverseAlias = "*ReverseAlias" + MetaAlias = "*Alias" + MetaUser = "*User" + MetaSubscribers = "*Subscribers" + MetaDerivedChargersV = "*DerivedChargers" + Migrator = "migrator" + UnsupportedMigrationTask = "unsupported migration task" + MetaTpRatingPlans = "*TpRatingPlans" + MetaTpLcrs = "*TpLcrs" + MetaTpFilters = "*TpFilters" + MetaTpDestinationRates = "*TpDestinationRates" + MetaTpActionTriggers = "*TpActionTriggers" + MetaTpAccountActions = "*TpAccountActions" + MetaTpActionPlans = "*TpActionPlans" + MetaTpActions = "*TpActions" + MetaTpDerivedCharges = "*TpDerivedCharges" + MetaTpThresholds = "*TpThresholds" + MetaTpStats = "*TpStats" + MetaTpSharedGroups = "*TpSharedGroups" + MetaTpRatingProfiles = "*TpRatingProfiles" + MetaTpResources = "*TpResources" + MetaTpRates = "*TpRates" + MetaTpTiming = "*TpTiming" + MetaTpResource = "*TpResource" + MetaTpAliases = "*TpAliases" + MetaTpUsers = "*TpUsers" + MetaTpDerivedChargersV = "*TpDerivedChargers" + MetaTpCdrStats = "*TpCdrStats" + MetaTpDestinations = "*TpDestinations" + MetaTpLCR = "*TpLCR" + MetaTpRatingPlan = "*TpRatingPlan" + MetaTpRatingProfile = "*TpRatingProfile" + MetaStorDB = "*StorDB" + MetaDataDB = "*DataDB" +) + +//versions +const ( + TpRatingPlans = "TpRatingPlans" + TpLcrs = "TpLcrs" + TpFilters = "TpFilters" + TpDestinationRates = "TpDestinationRates" + TpActionTriggers = "TpActionTriggers" + TpAccountActions = "TpAccountActions" + TpActionPlans = "TpActionPlans" + TpActions = "TpActions" + TpDerivedCharges = "TpDerivedCharges" + TpThresholds = "TpThresholds" + TpStats = "TpStats" + TpSharedGroups = "TpSharedGroups" + TpRatingProfiles = "TpRatingProfiles" + TpResources = "TpResources" + TpRates = "TpRates" + TpTiming = "TpTiming" + TpResource = "TpResource" + TpAliases = "TpAliases" + TpUsers = "TpUsers" + TpDerivedChargersV = "TpDerivedChargers" + TpCdrStats = "TpCdrStats" + TpDestinations = "TpDestinations" + TpLCR = "TpLCR" + TpRatingPlan = "TpRatingPlan" + TpRatingProfile = "TpRatingProfile" + Timing = "Timing" + RQF = "RQF" + Resource = "Resource" + ReverseAlias = "ReverseAlias" + Alias = "Alias" + User = "User" + Subscribers = "Subscribers" + DerivedChargersV = "DerivedChargers" + CdrStats = "CdrStats" + Destinations = "Destinations" + ReverseDestinations = "ReverseDestinations" + LCR = "LCR" + RatingPlan = "RatingPlan" + RatingProfile = "RatingProfile" +) + func buildCacheInstRevPrefixes() { CachePrefixToInstance = make(map[string]string) for k, v := range CacheInstanceToPrefix {