Removed storDB from Migrator

This commit is contained in:
andronache98
2022-03-07 16:35:08 +02:00
committed by Dan Christian Bogos
parent a678e88bcb
commit e342eea6fa
35 changed files with 49 additions and 2414 deletions

View File

@@ -112,9 +112,6 @@ func TestLoadConfig(t *testing.T) {
if ldrCfg.GeneralCfg().DefaultTimezone != utils.Local {
t.Errorf("Expected %s received %s", utils.Local, ldrCfg.GeneralCfg().DefaultTimezone)
}
if !reflect.DeepEqual(ldrCfg.StorDbCfg(), expStorDB) {
t.Errorf("Expected %s received %s", utils.ToJSON(expStorDB), utils.ToJSON(ldrCfg.StorDbCfg()))
}
if !ldrCfg.LoaderCgrCfg().DisableReverse {
t.Errorf("Expected %v received %v", true, ldrCfg.LoaderCgrCfg().DisableReverse)
}

View File

@@ -126,12 +126,6 @@ func TestCGRLoaderFlags(t *testing.T) {
t.Errorf("Expected /path/to/CACertificate, received %+v", *dbRedisCACertificate)
}
if err := cgrLoaderFlags.Parse([]string{"-stordb_port", "6533"}); err != nil {
t.Error(err)
} else if *storDBPort != "6533" {
t.Errorf("Expected 6533, received %+v", *storDBPort)
}
if err := cgrLoaderFlags.Parse([]string{"-caching", "*none"}); err != nil {
t.Error(err)
} else if *cachingArg != "*none" {

View File

@@ -36,19 +36,15 @@ var (
cgrMigratorFlags = flag.NewFlagSet(utils.CgrMigrator, flag.ContinueOnError)
sameDataDB bool
sameStorDB bool
sameOutDB bool
dmIN migrator.MigratorDataDB
dmOUT migrator.MigratorDataDB
storDBIn migrator.MigratorStorDB
storDBOut migrator.MigratorStorDB
err error
dfltCfg = config.NewDefaultCGRConfig()
cfgPath = cgrMigratorFlags.String(utils.CfgPathCgr, utils.EmptyString,
"Configuration directory path.")
exec = cgrMigratorFlags.String(utils.ExecCgr, utils.EmptyString, "fire up automatic migration "+
"<*set_versions|*cost_details|*accounts|*actions|*action_triggers|*action_plans|*shared_groups|*filters|*stordb|*datadb>")
"<*set_versions|*cost_details|*accounts|*actions|*action_triggers|*action_plans|*shared_groups|*filters|*datadb>")
version = cgrMigratorFlags.Bool(utils.VersionCgr, false, "prints the application version")
inDataDBType = cgrMigratorFlags.String(utils.DataDBTypeCgr, dfltCfg.DataDbCfg().Type,
@@ -96,33 +92,6 @@ var (
"the encoding used to store object Data in strings in move mode")
outDataDBRedisSentinel = cgrMigratorFlags.String(utils.OutDataDBRedisSentinel, utils.MetaDataDB,
"the name of redis sentinel")
inStorDBType = cgrMigratorFlags.String(utils.StorDBTypeCgr, dfltCfg.StorDbCfg().Type,
"the type of the StorDB Database <*mysql|*postgres|*mongo>")
inStorDBHost = cgrMigratorFlags.String(utils.StorDBHostCgr, dfltCfg.StorDbCfg().Host,
"the StorDB host")
inStorDBPort = cgrMigratorFlags.String(utils.StorDBPortCgr, dfltCfg.StorDbCfg().Port,
"the StorDB port")
inStorDBName = cgrMigratorFlags.String(utils.StorDBNameCgr, dfltCfg.StorDbCfg().Name,
"the name/number of the StorDB")
inStorDBUser = cgrMigratorFlags.String(utils.StorDBUserCgr, dfltCfg.StorDbCfg().User,
"the StorDB user")
inStorDBPass = cgrMigratorFlags.String(utils.StorDBPasswdCgr, dfltCfg.StorDbCfg().Password,
"the StorDB password")
outStorDBType = cgrMigratorFlags.String(utils.OutStorDBTypeCfg, utils.MetaStorDB,
"output StorDB type for move mode <*mysql|*postgres|*mongo>")
outStorDBHost = cgrMigratorFlags.String(utils.OutStorDBHostCfg, utils.MetaStorDB,
"output StorDB host")
outStorDBPort = cgrMigratorFlags.String(utils.OutStorDBPortCfg, utils.MetaStorDB,
"output StorDB port")
outStorDBName = cgrMigratorFlags.String(utils.OutStorDBNameCfg, utils.MetaStorDB,
"output StorDB name/number")
outStorDBUser = cgrMigratorFlags.String(utils.OutStorDBUserCfg, utils.MetaStorDB,
"output StorDB user")
outStorDBPass = cgrMigratorFlags.String(utils.OutStorDBPasswordCfg, utils.MetaStorDB,
"output StorDB password")
dryRun = cgrMigratorFlags.Bool(utils.DryRunCfg, false,
"parse loaded data for consistency and errors, without storing it")
verbose = cgrMigratorFlags.Bool(utils.VerboseCgr, false, "enable detailed verbose logging output")
@@ -298,103 +267,8 @@ func main() {
log.Fatal(err)
}
// inStorDB
if *inStorDBType != dfltCfg.StorDbCfg().Type {
mgrCfg.StorDbCfg().Type = strings.TrimPrefix(*inStorDBType, utils.MaskChar)
}
if *inStorDBHost != dfltCfg.StorDbCfg().Host {
mgrCfg.StorDbCfg().Host = *inStorDBHost
}
if *inStorDBPort != dfltCfg.StorDbCfg().Port {
mgrCfg.StorDbCfg().Port = *inStorDBPort
}
if *inStorDBName != dfltCfg.StorDbCfg().Name {
mgrCfg.StorDbCfg().Name = *inStorDBName
}
if *inStorDBUser != dfltCfg.StorDbCfg().User {
mgrCfg.StorDbCfg().User = *inStorDBUser
}
if *inStorDBPass != dfltCfg.StorDbCfg().Password {
mgrCfg.StorDbCfg().Password = *inStorDBPass
}
// outStorDB
if *outStorDBType == utils.MetaStorDB {
if dfltCfg.MigratorCgrCfg().OutStorDBType == mgrCfg.MigratorCgrCfg().OutStorDBType {
mgrCfg.MigratorCgrCfg().OutStorDBType = mgrCfg.StorDbCfg().Type
}
} else {
mgrCfg.MigratorCgrCfg().OutStorDBType = strings.TrimPrefix(*outStorDBType, utils.MaskChar)
}
if *outStorDBHost == utils.MetaStorDB {
if dfltCfg.MigratorCgrCfg().OutStorDBHost == mgrCfg.MigratorCgrCfg().OutStorDBHost {
mgrCfg.MigratorCgrCfg().OutStorDBHost = mgrCfg.StorDbCfg().Host
}
} else {
mgrCfg.MigratorCgrCfg().OutStorDBHost = *outStorDBHost
}
if *outStorDBPort == utils.MetaStorDB {
if dfltCfg.MigratorCgrCfg().OutStorDBPort == mgrCfg.MigratorCgrCfg().OutStorDBPort {
mgrCfg.MigratorCgrCfg().OutStorDBPort = mgrCfg.StorDbCfg().Port
}
} else {
mgrCfg.MigratorCgrCfg().OutStorDBPort = *outStorDBPort
}
if *outStorDBName == utils.MetaStorDB {
if dfltCfg.MigratorCgrCfg().OutStorDBName == mgrCfg.MigratorCgrCfg().OutStorDBName {
mgrCfg.MigratorCgrCfg().OutStorDBName = mgrCfg.StorDbCfg().Name
}
} else {
mgrCfg.MigratorCgrCfg().OutStorDBName = *outStorDBName
}
if *outStorDBUser == utils.MetaStorDB {
if dfltCfg.MigratorCgrCfg().OutStorDBUser == mgrCfg.MigratorCgrCfg().OutStorDBUser {
mgrCfg.MigratorCgrCfg().OutStorDBUser = mgrCfg.StorDbCfg().User
}
} else {
mgrCfg.MigratorCgrCfg().OutStorDBUser = *outStorDBUser
}
if *outStorDBPass == utils.MetaStorDB {
if dfltCfg.MigratorCgrCfg().OutStorDBPassword == mgrCfg.MigratorCgrCfg().OutStorDBPassword {
mgrCfg.MigratorCgrCfg().OutStorDBPassword = mgrCfg.StorDbCfg().Password
}
} else {
mgrCfg.MigratorCgrCfg().OutStorDBPassword = *outStorDBPass
}
sameStorDB = mgrCfg.MigratorCgrCfg().OutStorDBType == mgrCfg.StorDbCfg().Type &&
mgrCfg.MigratorCgrCfg().OutStorDBHost == mgrCfg.StorDbCfg().Host &&
mgrCfg.MigratorCgrCfg().OutStorDBPort == mgrCfg.StorDbCfg().Port &&
mgrCfg.MigratorCgrCfg().OutStorDBName == mgrCfg.StorDbCfg().Name
if storDBIn, err = migrator.NewMigratorStorDB(mgrCfg.StorDbCfg().Type,
mgrCfg.StorDbCfg().Host, mgrCfg.StorDbCfg().Port,
mgrCfg.StorDbCfg().Name, mgrCfg.StorDbCfg().User,
mgrCfg.StorDbCfg().Password, mgrCfg.GeneralCfg().DBDataEncoding,
mgrCfg.StorDbCfg().StringIndexedFields, mgrCfg.StorDbCfg().PrefixIndexedFields,
mgrCfg.StorDbCfg().Opts, mgrCfg.StorDbCfg().Items); err != nil {
log.Fatal(err)
}
if sameStorDB {
storDBOut = storDBIn
} else if storDBOut, err = migrator.NewMigratorStorDB(mgrCfg.MigratorCgrCfg().OutStorDBType,
mgrCfg.MigratorCgrCfg().OutStorDBHost, mgrCfg.MigratorCgrCfg().OutStorDBPort,
mgrCfg.MigratorCgrCfg().OutStorDBName, mgrCfg.MigratorCgrCfg().OutStorDBUser,
mgrCfg.MigratorCgrCfg().OutStorDBPassword, mgrCfg.GeneralCfg().DBDataEncoding,
mgrCfg.StorDbCfg().StringIndexedFields, mgrCfg.StorDbCfg().PrefixIndexedFields,
mgrCfg.MigratorCgrCfg().OutStorDBOpts, mgrCfg.StorDbCfg().Items); err != nil {
log.Fatal(err)
}
sameOutDB = mgrCfg.MigratorCgrCfg().OutStorDBType == mgrCfg.MigratorCgrCfg().OutDataDBType &&
mgrCfg.MigratorCgrCfg().OutStorDBHost == mgrCfg.MigratorCgrCfg().OutDataDBHost &&
mgrCfg.MigratorCgrCfg().OutStorDBPort == mgrCfg.MigratorCgrCfg().OutDataDBPort &&
mgrCfg.MigratorCgrCfg().OutStorDBName == mgrCfg.MigratorCgrCfg().OutDataDBName
m, err := migrator.NewMigrator(dmIN, dmOUT,
storDBIn, storDBOut,
*dryRun, sameDataDB, sameStorDB, sameOutDB)
*dryRun, sameDataDB)
if err != nil {
log.Fatal(err)
}

View File

@@ -161,66 +161,7 @@ func TestFlags(t *testing.T) {
} else if *outDataDBRedisSentinel != "true" {
t.Errorf("Expected true received:%v ", *outDataDBRedisSentinel)
}
if err := cgrMigratorFlags.Parse([]string{"-stordb_type", "true"}); err != nil {
t.Fatal(err)
} else if *inStorDBType != "true" {
t.Errorf("Expected true received:%v ", *inStorDBType)
}
if err := cgrMigratorFlags.Parse([]string{"-stordb_host", "true"}); err != nil {
t.Fatal(err)
} else if *inStorDBHost != "true" {
t.Errorf("Expected true received:%v ", *inStorDBHost)
}
if err := cgrMigratorFlags.Parse([]string{"-stordb_port", "true"}); err != nil {
t.Fatal(err)
} else if *inStorDBPort != "true" {
t.Errorf("Expected true received:%v ", *inStorDBPort)
}
if err := cgrMigratorFlags.Parse([]string{"-stordb_name", "true"}); err != nil {
t.Fatal(err)
} else if *inStorDBName != "true" {
t.Errorf("Expected true received:%v ", *inStorDBName)
}
if err := cgrMigratorFlags.Parse([]string{"-stordb_user", "true"}); err != nil {
t.Fatal(err)
} else if *inStorDBUser != "true" {
t.Errorf("Expected true received:%v ", *inStorDBUser)
}
if err := cgrMigratorFlags.Parse([]string{"-stordb_passwd", "true"}); err != nil {
t.Fatal(err)
} else if *inStorDBPass != "true" {
t.Errorf("Expected true received:%v ", *inStorDBPass)
}
if err := cgrMigratorFlags.Parse([]string{"-out_stordb_type", "true"}); err != nil {
t.Fatal(err)
} else if *outStorDBType != "true" {
t.Errorf("Expected true received:%v ", *outStorDBType)
}
if err := cgrMigratorFlags.Parse([]string{"-out_stordb_host", "true"}); err != nil {
t.Fatal(err)
} else if *outStorDBHost != "true" {
t.Errorf("Expected true received:%v ", *outStorDBHost)
}
if err := cgrMigratorFlags.Parse([]string{"-out_stordb_port", "true"}); err != nil {
t.Fatal(err)
} else if *outStorDBPort != "true" {
t.Errorf("Expected true received:%v ", *outStorDBPort)
}
if err := cgrMigratorFlags.Parse([]string{"-out_stordb_name", "true"}); err != nil {
t.Fatal(err)
} else if *outStorDBName != "true" {
t.Errorf("Expected true received:%v ", *outStorDBName)
}
if err := cgrMigratorFlags.Parse([]string{"-out_stordb_user", "true"}); err != nil {
t.Fatal(err)
} else if *outStorDBUser != "true" {
t.Errorf("Expected true received:%v ", *outStorDBUser)
}
if err := cgrMigratorFlags.Parse([]string{"-out_stordb_password", "true"}); err != nil {
t.Fatal(err)
} else if *outStorDBPass != "true" {
t.Errorf("Expected true received:%v ", *outStorDBPass)
}
if err := cgrMigratorFlags.Parse([]string{"-dry_run", "true"}); err != nil {
t.Fatal(err)
} else if !*dryRun {

View File

@@ -374,12 +374,6 @@ func storeDiffSection(ctx *context.Context, section string, db ConfigDB, v1, v2
return
}
return db.SetSection(ctx, section, diffHTTPJsonCfg(jsn, v1.HTTPCfg(), v2.HTTPCfg()))
case StorDBJSON:
jsn := new(DbJsonCfg)
if err = db.GetSection(ctx, section, jsn); err != nil {
return
}
return db.SetSection(ctx, section, diffStorDBDbJsonCfg(jsn, v1.StorDbCfg(), v2.StorDbCfg()))
case DataDBJSON:
jsn := new(DbJsonCfg)
if err = db.GetSection(ctx, section, jsn); err != nil {

View File

@@ -219,11 +219,11 @@ func testAttrITConnect(t *testing.T) {
}
if reflect.DeepEqual(attrPathIn, attrPathOut) {
attrMigrator, err = NewMigrator(dataDBIn, dataDBOut, nil, nil,
false, true, false, false)
attrMigrator, err = NewMigrator(dataDBIn, dataDBOut,
false, true)
} else {
attrMigrator, err = NewMigrator(dataDBIn, dataDBOut, nil, nil,
false, false, false, false)
attrMigrator, err = NewMigrator(dataDBIn, dataDBOut,
false, false)
}
if err != nil {
log.Fatal(err)

View File

@@ -143,11 +143,11 @@ func testChrgITConnect(t *testing.T) {
log.Fatal(err)
}
if reflect.DeepEqual(chrgPathIn, chrgPathOut) {
chrgMigrator, err = NewMigrator(dataDBIn, dataDBOut, nil, nil,
false, true, false, false)
chrgMigrator, err = NewMigrator(dataDBIn, dataDBOut,
false, true)
} else {
chrgMigrator, err = NewMigrator(dataDBIn, dataDBOut, nil, nil,
false, false, false, false)
chrgMigrator, err = NewMigrator(dataDBIn, dataDBOut,
false, false)
}
if err != nil {
log.Fatal(err)

View File

@@ -139,11 +139,11 @@ func testDspITConnect(t *testing.T) {
log.Fatal(err)
}
if reflect.DeepEqual(dspPathIn, dspPathOut) {
dspMigrator, err = NewMigrator(dataDBIn, dataDBOut, nil, nil,
false, true, false, false)
dspMigrator, err = NewMigrator(dataDBIn, dataDBOut,
false, true)
} else {
dspMigrator, err = NewMigrator(dataDBIn, dataDBOut, nil, nil,
false, false, false, false)
dspMigrator, err = NewMigrator(dataDBIn, dataDBOut,
false, false)
}
if err != nil {
log.Fatal(err)

View File

@@ -119,11 +119,11 @@ func testFltrITConnect(t *testing.T) {
log.Fatal(err)
}
if reflect.DeepEqual(inPath, outPath) {
fltrMigrator, err = NewMigrator(dataDBIn, dataDBOut, nil, nil,
false, true, false, false)
fltrMigrator, err = NewMigrator(dataDBIn, dataDBOut,
false, true)
} else {
fltrMigrator, err = NewMigrator(dataDBIn, dataDBOut, nil, nil,
false, false, false, false)
fltrMigrator, err = NewMigrator(dataDBIn, dataDBOut,
false, false)
}
if err != nil {
log.Fatal(err)

View File

@@ -94,10 +94,10 @@ func testLoadIdsITConnect(t *testing.T) {
}
if inPath == outPath {
loadMigrator, err = NewMigrator(dataDBIn, dataDBOut,
nil, nil, false, true, false, false)
false, true)
} else {
loadMigrator, err = NewMigrator(dataDBIn, dataDBOut,
nil, nil, false, false, false, false)
false, false)
}
if err != nil {
log.Fatal(err)

View File

@@ -27,18 +27,13 @@ import (
)
func NewMigrator(dmIN, dmOut MigratorDataDB,
storDBIn, storDBOut MigratorStorDB,
dryRun, sameDataDB, sameStorDB, sameOutDB bool) (m *Migrator, err error) {
dryRun, sameDataDB bool) (m *Migrator, err error) {
stats := make(map[string]int)
m = &Migrator{
dmOut: dmOut,
dmIN: dmIN,
storDBIn: storDBIn,
storDBOut: storDBOut,
dryRun: dryRun,
sameDataDB: sameDataDB,
sameStorDB: sameStorDB,
sameOutDB: sameOutDB,
stats: stats,
}
return m, err
@@ -47,12 +42,8 @@ func NewMigrator(dmIN, dmOut MigratorDataDB,
type Migrator struct {
dmIN MigratorDataDB
dmOut MigratorDataDB
storDBIn MigratorStorDB
storDBOut MigratorStorDB
dryRun bool
sameDataDB bool
sameStorDB bool
sameOutDB bool // needed in case we set version and we use same DataDB as StorDB to store the versions without overwriting them
stats map[string]int
}
@@ -76,24 +67,11 @@ func (m *Migrator) Migrate(taskIDs []string) (err error, stats map[string]int) {
return utils.NewCGRError(utils.Migrator, utils.ServerErrorCaps, err.Error(),
fmt.Sprintf("error: <%s> when seting versions for DataDB", err.Error())), nil
}
if m.sameOutDB {
err = engine.SetDBVersions(m.storDBOut.StorDB())
} else {
err = engine.OverwriteDBVersions(m.storDBOut.StorDB())
}
if err != nil {
return utils.NewCGRError(utils.Migrator, utils.ServerErrorCaps, err.Error(),
fmt.Sprintf("error: <%s> when seting versions for StorDB", err.Error())), nil
}
case utils.MetaEnsureIndexes:
if m.storDBOut.StorDB().GetStorageType() == utils.Mongo {
mgo := m.storDBOut.StorDB().(*engine.MongoStorage)
if err = mgo.EnsureIndexes(); err != nil {
return
}
} else {
log.Printf("The StorDB type has to be %s .\n ", utils.Mongo)
}
if m.dmOut.DataManager().DataDB().GetStorageType() == utils.Mongo {
mgo := m.dmOut.DataManager().DataDB().(*engine.MongoStorage)
@@ -130,24 +108,6 @@ func (m *Migrator) Migrate(taskIDs []string) (err error, stats map[string]int) {
case utils.MetaDispatchers:
err = m.migrateDispatchers()
//TPs
case utils.MetaTpFilters:
err = m.migrateTPfilters()
case utils.MetaTpThresholds:
err = m.migrateTPthresholds()
case utils.MetaTpRoutes:
err = m.migrateTPRoutes()
case utils.MetaTpStats:
err = m.migrateTPstats()
case utils.MetaTpRateProfiles:
err = m.migrateTPRateProfiles()
case utils.MetaTpActionProfiles:
err = m.migrateTPActionProfiles()
case utils.MetaTpResources:
err = m.migrateTPresources()
case utils.MetaTpChargers:
err = m.migrateTPChargers()
case utils.MetaTpDispatchers:
err = m.migrateTPDispatchers()
case utils.MetaLoadIDs:
err = m.migrateLoadIDs()
//DATADB ALL
@@ -180,30 +140,7 @@ func (m *Migrator) Migrate(taskIDs []string) (err error, stats map[string]int) {
log.Print("ERROR: ", utils.MetaLoadIDs, " ", err)
}
err = nil
//STORDB ALL
case utils.MetaStorDB:
if err := m.migrateTPfilters(); err != nil {
log.Print("ERROR: ", utils.MetaTpFilters, " ", err)
}
if err := m.migrateTPthresholds(); err != nil {
log.Print("ERROR: ", utils.MetaTpThresholds, " ", err)
}
if err := m.migrateTPRoutes(); err != nil {
log.Print("ERROR: ", utils.MetaTpRoutes, " ", err)
}
if err := m.migrateTPstats(); err != nil {
log.Print("ERROR: ", utils.MetaTpStats, " ", err)
}
if err := m.migrateTPresources(); err != nil {
log.Print("ERROR: ", utils.MetaTpResources, " ", err)
}
if err := m.migrateTPChargers(); err != nil {
log.Print("ERROR: ", utils.MetaTpChargers, " ", err)
}
if err := m.migrateTPDispatchers(); err != nil {
log.Print("ERROR: ", utils.MetaTpDispatchers, " ", err)
}
err = nil
}
}
for k, v := range m.stats {
@@ -220,14 +157,6 @@ func (m *Migrator) ensureIndexesDataDB(cols ...string) error {
return mgo.EnsureIndexes(cols...)
}
func (m *Migrator) ensureIndexesStorDB(cols ...string) error {
if m.storDBOut.StorDB().GetStorageType() != utils.Mongo {
return nil
}
mgo := m.storDBOut.StorDB().(*engine.MongoStorage)
return mgo.EnsureIndexes(cols...)
}
// closes all opened DBs
func (m *Migrator) Close() {
if m.dmIN != nil {
@@ -236,10 +165,4 @@ func (m *Migrator) Close() {
if m.dmOut != nil {
m.dmOut.close()
}
if m.storDBIn != nil {
m.storDBIn.close()
}
if m.storDBOut != nil {
m.storDBOut.close()
}
}

View File

@@ -20,7 +20,6 @@ package migrator
import (
"fmt"
"strings"
"github.com/cgrates/cgrates/config"
"github.com/cgrates/cgrates/engine"
@@ -81,11 +80,7 @@ func NewMigratorStorDB(db_type, host, port, name, user, pass, marshaler string,
return
}
func (m *Migrator) getVersions(str string) (vrs engine.Versions, err error) {
if str == utils.CDRs || str == utils.SessionSCosts || strings.HasPrefix(str, "Tp") {
vrs, err = m.storDBIn.StorDB().GetVersions(utils.EmptyString)
} else {
vrs, err = m.dmIN.DataManager().DataDB().GetVersions(utils.EmptyString)
}
vrs, err = m.dmIN.DataManager().DataDB().GetVersions(utils.EmptyString)
if err != nil {
return nil, utils.NewCGRError(utils.Migrator,
utils.ServerErrorCaps,
@@ -101,18 +96,13 @@ func (m *Migrator) getVersions(str string) (vrs engine.Versions, err error) {
}
func (m *Migrator) setVersions(str string) (err error) {
if str == utils.CDRs || str == utils.SessionSCosts || strings.HasPrefix(str, "Tp") {
vrs := engine.Versions{str: engine.CurrentStorDBVersions()[str]}
err = m.storDBOut.StorDB().SetVersions(vrs, false)
} else {
vrs := engine.Versions{str: engine.CurrentDataDBVersions()[str]}
err = m.dmOut.DataManager().DataDB().SetVersions(vrs, false)
}
vrs := engine.Versions{str: engine.CurrentDataDBVersions()[str]}
err = m.dmOut.DataManager().DataDB().SetVersions(vrs, false)
if err != nil {
err = utils.NewCGRError(utils.Migrator,
utils.ServerErrorCaps,
err.Error(),
fmt.Sprintf("error: <%s> when updating %s version into StorDB", err.Error(), str))
fmt.Sprintf("error: <%s> when updating %s version into DataDB", err.Error(), str))
}
return
}

View File

@@ -142,11 +142,11 @@ func testRatePrfITConnect(t *testing.T) {
log.Fatal(err)
}
if reflect.DeepEqual(ratePrfPathIn, ratePrfPathOut) {
ratePrfMigrator, err = NewMigrator(dataDBIn, dataDBOut, nil, nil,
false, true, false, false)
ratePrfMigrator, err = NewMigrator(dataDBIn, dataDBOut,
false, true)
} else {
ratePrfMigrator, err = NewMigrator(dataDBIn, dataDBOut, nil, nil,
false, false, false, false)
ratePrfMigrator, err = NewMigrator(dataDBIn, dataDBOut,
false, false)
}
if err != nil {
log.Fatal(err)

View File

@@ -143,11 +143,11 @@ func testResITConnect(t *testing.T) {
log.Fatal(err)
}
if reflect.DeepEqual(resPathIn, resPathOut) {
resMigrator, err = NewMigrator(dataDBIn, dataDBOut, nil, nil,
false, true, false, false)
resMigrator, err = NewMigrator(dataDBIn, dataDBOut,
false, true)
} else {
resMigrator, err = NewMigrator(dataDBIn, dataDBOut, nil, nil,
false, false, false, false)
resMigrator, err = NewMigrator(dataDBIn, dataDBOut,
false, false)
}
if err != nil {
log.Fatal(err)

View File

@@ -142,11 +142,11 @@ func testSupITConnect(t *testing.T) {
log.Fatal(err)
}
if reflect.DeepEqual(supPathIn, supPathOut) {
supMigrator, err = NewMigrator(dataDBIn, dataDBOut, nil, nil,
false, true, false, false)
supMigrator, err = NewMigrator(dataDBIn, dataDBOut,
false, true)
} else {
supMigrator, err = NewMigrator(dataDBIn, dataDBOut, nil, nil,
false, false, false, false)
supMigrator, err = NewMigrator(dataDBIn, dataDBOut,
false, false)
}
if err != nil {
log.Fatal(err)

View File

@@ -125,11 +125,11 @@ func testStsITConnect(t *testing.T) {
log.Fatal(err)
}
if stsPathIn == stsPathOut {
stsMigrator, err = NewMigrator(dataDBIn, dataDBOut, nil, nil,
false, true, false, false)
stsMigrator, err = NewMigrator(dataDBIn, dataDBOut,
false, true)
} else {
stsMigrator, err = NewMigrator(dataDBIn, dataDBOut, nil, nil,
false, false, false, false)
stsMigrator, err = NewMigrator(dataDBIn, dataDBOut,
false, false)
}
if err != nil {
log.Fatal(err)

View File

@@ -161,11 +161,11 @@ func testTrsITConnect(t *testing.T) {
log.Fatal(err)
}
if reflect.DeepEqual(trsPathIn, trsPathOut) {
trsMigrator, err = NewMigrator(dataDBIn, dataDBOut, nil, nil,
false, true, false, false)
trsMigrator, err = NewMigrator(dataDBIn, dataDBOut,
false, true)
} else {
trsMigrator, err = NewMigrator(dataDBIn, dataDBOut, nil, nil,
false, false, false, false)
trsMigrator, err = NewMigrator(dataDBIn, dataDBOut,
false, false)
}
if err != nil {

View File

@@ -1,79 +0,0 @@
/*
Real-time Online/Offline Charging System (OCS) for Telecom & ISP environments
Copyright (C) ITsysCOM GmbH
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>
*/
package migrator
import (
"github.com/cgrates/cgrates/engine"
"github.com/cgrates/cgrates/utils"
)
func (m *Migrator) migrateCurrentTPActionProfiles() (err error) {
tpIds, err := m.storDBIn.StorDB().GetTpIds(utils.TBLTPActionProfiles)
if err != nil {
return err
}
for _, tpid := range tpIds {
ids, err := m.storDBIn.StorDB().GetTpTableIds(tpid, utils.TBLTPActionProfiles,
[]string{"id"}, map[string]string{}, nil)
if err != nil {
return err
}
for _, id := range ids {
actionProfiles, err := m.storDBIn.StorDB().GetTPActionProfiles(tpid, utils.EmptyString, id)
if err != nil {
return err
}
if actionProfiles == nil || m.dryRun {
continue
}
if err := m.storDBOut.StorDB().SetTPActionProfiles(actionProfiles); err != nil {
return err
}
for _, actionProfile := range actionProfiles {
if err := m.storDBIn.StorDB().RemTpData(utils.TBLTPActionProfiles, actionProfile.TPid,
map[string]string{"id": actionProfile.ID}); err != nil {
return err
}
}
m.stats[utils.TpActionProfiles]++
}
}
return
}
func (m *Migrator) migrateTPActionProfiles() (err error) {
var vrs engine.Versions
current := engine.CurrentStorDBVersions()
if vrs, err = m.getVersions(utils.TpActionProfiles); err != nil {
return
}
switch vrs[utils.TpActionProfiles] {
case current[utils.TpActionProfiles]:
if m.sameStorDB {
break
}
if err := m.migrateCurrentTPActionProfiles(); err != nil {
return err
}
}
return m.ensureIndexesStorDB(utils.TBLTPActionProfiles)
}

View File

@@ -1,169 +0,0 @@
//go:build integration
// +build integration
/*
Real-time Online/Offline Charging System (OCS) for Telecom & ISP environments
Copyright (C) ITsysCOM GmbH
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>
*/
package migrator
import (
"path"
"reflect"
"testing"
"github.com/cgrates/birpc/context"
"github.com/cgrates/cgrates/engine"
"github.com/cgrates/cgrates/config"
"github.com/cgrates/cgrates/utils"
)
var (
tpActPrfPathIn string
tpActPrfPathOut string
tpActPrfCfgIn *config.CGRConfig
tpActPrfCfgOut *config.CGRConfig
tpActPrfMigrator *Migrator
actPrf []*utils.TPActionProfile
)
var sTestTpActPrfIT = []func(t *testing.T){
testTpActPrfConnect,
testTpActPrfFlush,
testTpACtPrfPopulate,
testTpACtPrfMove,
testTpACtPrfCheckData,
}
func TestTpActPrfMove(t *testing.T) {
for _, tests := range sTestTpActPrfIT {
t.Run("TestTpActPrfMove", tests)
}
tpActPrfMigrator.Close()
}
func testTpActPrfConnect(t *testing.T) {
var err error
tpActPrfPathIn = path.Join(*dataDir, "conf", "samples", "tutmongo")
tpActPrfCfgIn, err = config.NewCGRConfigFromPath(context.Background(), tpActPrfPathIn)
if err != nil {
t.Fatal(err)
}
tpActPrfPathOut = path.Join(*dataDir, "conf", "samples", "tutmysql")
tpActPrfCfgOut, err = config.NewCGRConfigFromPath(context.Background(), tpActPrfPathOut)
if err != nil {
t.Fatal(err)
}
storDBIn, err := NewMigratorStorDB(tpActPrfCfgIn.StorDbCfg().Type,
tpActPrfCfgIn.StorDbCfg().Host, tpActPrfCfgIn.StorDbCfg().Port,
tpActPrfCfgIn.StorDbCfg().Name, tpActPrfCfgIn.StorDbCfg().User,
tpActPrfCfgIn.StorDbCfg().Password, tpActPrfCfgIn.GeneralCfg().DBDataEncoding,
tpActPrfCfgIn.StorDbCfg().StringIndexedFields, tpActPrfCfgIn.StorDbCfg().PrefixIndexedFields,
tpActPrfCfgIn.StorDbCfg().Opts, tpActPrfCfgIn.StorDbCfg().Items)
if err != nil {
t.Error(err)
}
storDBOut, err := NewMigratorStorDB(tpActPrfCfgOut.StorDbCfg().Type,
tpActPrfCfgOut.StorDbCfg().Host, tpActPrfCfgOut.StorDbCfg().Port,
tpActPrfCfgOut.StorDbCfg().Name, tpActPrfCfgOut.StorDbCfg().User,
tpActPrfCfgOut.StorDbCfg().Password, tpActPrfCfgOut.GeneralCfg().DBDataEncoding,
tpActPrfCfgOut.StorDbCfg().StringIndexedFields, tpActPrfCfgOut.StorDbCfg().PrefixIndexedFields,
tpActPrfCfgOut.StorDbCfg().Opts, tpActPrfCfgOut.StorDbCfg().Items)
if err != nil {
t.Error(err)
}
tpActPrfMigrator, err = NewMigrator(nil, nil, storDBIn, storDBOut,
false, false, false, false)
if err != nil {
t.Fatal(err)
}
}
func testTpActPrfFlush(t *testing.T) {
if err := tpActPrfMigrator.storDBIn.StorDB().Flush(
path.Join(tpActPrfCfgIn.DataFolderPath, "storage", tpActPrfCfgIn.StorDbCfg().Type)); err != nil {
t.Error(err)
}
if err := tpActPrfMigrator.storDBOut.StorDB().Flush(
path.Join(tpActPrfCfgOut.DataFolderPath, "storage", tpActPrfCfgOut.StorDbCfg().Type)); err != nil {
t.Error(err)
}
}
func testTpACtPrfPopulate(t *testing.T) {
actPrf = []*utils.TPActionProfile{
{
Tenant: "cgrates.org",
TPid: "TEST_ID1",
ID: "sub_id1",
FilterIDs: []string{"*string:~*req.Account:1001"},
Weights: ";20",
Schedule: utils.MetaASAP,
Actions: []*utils.TPAPAction{
{
ID: "TOPUP",
FilterIDs: []string{},
Type: "*topup",
Diktats: []*utils.TPAPDiktat{{
Path: "~*balance.TestBalance.Value",
}},
},
},
},
}
//empty in database
if _, err := tpActPrfMigrator.storDBIn.StorDB().GetTPActionProfiles(actPrf[0].TPid,
utils.EmptyString, actPrf[0].ID); err != utils.ErrNotFound {
t.Error(err)
}
//set an TPActionProfile in database
if err := tpActPrfMigrator.storDBIn.StorDB().SetTPActionProfiles(actPrf); err != nil {
t.Error(err)
}
currVersion := engine.CurrentStorDBVersions()
err := tpActPrfMigrator.storDBIn.StorDB().SetVersions(currVersion, false)
if err != nil {
t.Error(err)
}
}
func testTpACtPrfMove(t *testing.T) {
err, _ := tpActPrfMigrator.Migrate([]string{utils.MetaTpActionProfiles})
if err != nil {
t.Error("Error when migrating TpActionProfile ", err.Error())
}
}
func testTpACtPrfCheckData(t *testing.T) {
rcv, err := tpActPrfMigrator.storDBOut.StorDB().GetTPActionProfiles(actPrf[0].TPid,
utils.EmptyString, actPrf[0].ID)
if err != nil {
t.Error("Error when getting TPActionProfile from database", err)
}
actPrf[0].Actions[0].FilterIDs = nil // because of converting and empty string into a slice
if !reflect.DeepEqual(rcv[0], actPrf[0]) {
t.Errorf("Expecting: %+v, received: %+v", utils.ToJSON(actPrf[0]), utils.ToJSON(rcv[0]))
}
_, err = tpActPrfMigrator.storDBIn.StorDB().GetTPActionProfiles(actPrf[0].TPid,
utils.EmptyString, actPrf[0].ID)
if err != utils.ErrNotFound {
t.Error(err)
}
}

View File

@@ -1,77 +0,0 @@
/*
Real-time Online/Offline Charging System (OCS) for Telecom & ISP environments
Copyright (C) ITsysCOM GmbH
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>
*/
package migrator
import (
"github.com/cgrates/cgrates/engine"
"github.com/cgrates/cgrates/utils"
)
func (m *Migrator) migrateCurrentTPChargers() (err error) {
tpids, err := m.storDBIn.StorDB().GetTpIds(utils.TBLTPChargers)
if err != nil {
return err
}
for _, tpid := range tpids {
ids, err := m.storDBIn.StorDB().GetTpTableIds(tpid, utils.TBLTPChargers,
[]string{"id"}, map[string]string{}, nil)
if err != nil {
return err
}
for _, id := range ids {
chargers, err := m.storDBIn.StorDB().GetTPChargers(tpid, "", id)
if err != nil {
return err
}
if chargers == nil || m.dryRun {
continue
}
if err := m.storDBOut.StorDB().SetTPChargers(chargers); err != nil {
return err
}
for _, charger := range chargers {
if err := m.storDBIn.StorDB().RemTpData(utils.TBLTPChargers, charger.TPid,
map[string]string{"id": charger.ID}); err != nil {
return err
}
}
m.stats[utils.TpChargers]++
}
}
return
}
func (m *Migrator) migrateTPChargers() (err error) {
var vrs engine.Versions
current := engine.CurrentStorDBVersions()
if vrs, err = m.getVersions(utils.TpChargers); err != nil {
return
}
switch vrs[utils.TpChargers] {
case current[utils.TpChargers]:
if m.sameStorDB {
break
}
if err := m.migrateCurrentTPChargers(); err != nil {
return err
}
}
return m.ensureIndexesStorDB(utils.TBLTPChargers)
}

View File

@@ -1,114 +0,0 @@
/*
Real-time Online/Offline Charging System (OCS) for Telecom & ISP environments
Copyright (C) ITsysCOM GmbH
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>
*/
package migrator
import (
"github.com/cgrates/cgrates/engine"
"github.com/cgrates/cgrates/utils"
)
func (m *Migrator) migrateCurrentTPDispatchers() (err error) {
tpids, err := m.storDBIn.StorDB().GetTpIds(utils.TBLTPDispatchers)
if err != nil {
return err
}
for _, tpid := range tpids {
ids, err := m.storDBIn.StorDB().GetTpTableIds(tpid, utils.TBLTPDispatchers,
[]string{"id"}, map[string]string{}, nil)
if err != nil {
return err
}
for _, id := range ids {
dispatchers, err := m.storDBIn.StorDB().GetTPDispatcherProfiles(tpid, "", id)
if err != nil {
return err
}
if dispatchers == nil || m.dryRun {
continue
}
if err := m.storDBOut.StorDB().SetTPDispatcherProfiles(dispatchers); err != nil {
return err
}
for _, dispatcher := range dispatchers {
if err := m.storDBIn.StorDB().RemTpData(utils.TBLTPDispatchers, dispatcher.TPid,
map[string]string{"id": dispatcher.ID}); err != nil {
return err
}
}
m.stats[utils.TpDispatchers]++
}
}
return
}
func (m *Migrator) migrateCurrentTPDispatcherHosts() (err error) {
tpids, err := m.storDBIn.StorDB().GetTpIds(utils.TBLTPDispatcherHosts)
if err != nil {
return err
}
for _, tpid := range tpids {
ids, err := m.storDBIn.StorDB().GetTpTableIds(tpid, utils.TBLTPDispatcherHosts,
[]string{"id"}, map[string]string{}, nil)
if err != nil {
return err
}
for _, id := range ids {
dispatchers, err := m.storDBIn.StorDB().GetTPDispatcherHosts(tpid, "", id)
if err != nil {
return err
}
if dispatchers == nil || m.dryRun {
continue
}
if err := m.storDBOut.StorDB().SetTPDispatcherHosts(dispatchers); err != nil {
return err
}
for _, dispatcher := range dispatchers {
if err := m.storDBIn.StorDB().RemTpData(utils.TBLTPDispatcherHosts, dispatcher.TPid,
map[string]string{"id": dispatcher.ID}); err != nil {
return err
}
}
}
}
return
}
func (m *Migrator) migrateTPDispatchers() (err error) {
var vrs engine.Versions
current := engine.CurrentStorDBVersions()
if vrs, err = m.getVersions(utils.TpDispatchers); err != nil {
return
}
switch vrs[utils.TpDispatchers] {
case current[utils.TpDispatchers]:
if m.sameStorDB {
break
}
if err := m.migrateCurrentTPDispatchers(); err != nil {
return err
}
if err := m.migrateCurrentTPDispatcherHosts(); err != nil {
return err
}
}
return m.ensureIndexesStorDB(utils.TBLTPDispatchers, utils.TBLTPDispatcherHosts)
}

View File

@@ -1,154 +0,0 @@
//go:build integration
// +build integration
/*
Real-time Online/Offline Charging System (OCS) for Telecom & ISP environments
Copyright (C) ITsysCOM GmbH
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>
*/
package migrator
import (
"log"
"path"
"reflect"
"sort"
"testing"
"github.com/cgrates/birpc/context"
"github.com/cgrates/cgrates/config"
"github.com/cgrates/cgrates/engine"
"github.com/cgrates/cgrates/utils"
)
var (
tpDispPathIn string
tpDispPathOut string
tpDispCfgIn *config.CGRConfig
tpDispCfgOut *config.CGRConfig
tpDispMigrator *Migrator
tpDisps []*utils.TPDispatcherProfile
)
var sTestsTpDispIT = []func(t *testing.T){
testTpDispITConnect,
testTpDispITFlush,
testTpDispITPopulate,
testTpDispITMove,
testTpDispITCheckData,
}
func TestTpDispMove(t *testing.T) {
for _, stest := range sTestsTpDispIT {
t.Run("TestTpDispMove", stest)
}
tpDispMigrator.Close()
}
func testTpDispITConnect(t *testing.T) {
var err error
tpDispPathIn = path.Join(*dataDir, "conf", "samples", "tutmongo")
tpDispCfgIn, err = config.NewCGRConfigFromPath(context.Background(), tpDispPathIn)
if err != nil {
t.Fatal(err)
}
tpDispPathOut = path.Join(*dataDir, "conf", "samples", "tutmysql")
tpDispCfgOut, err = config.NewCGRConfigFromPath(context.Background(), tpDispPathOut)
if err != nil {
t.Fatal(err)
}
storDBIn, err := NewMigratorStorDB(tpDispCfgIn.StorDbCfg().Type,
tpDispCfgIn.StorDbCfg().Host, tpDispCfgIn.StorDbCfg().Port,
tpDispCfgIn.StorDbCfg().Name, tpDispCfgIn.StorDbCfg().User,
tpDispCfgIn.StorDbCfg().Password, tpDispCfgIn.GeneralCfg().DBDataEncoding,
tpDispCfgIn.StorDbCfg().StringIndexedFields, tpDispCfgIn.StorDbCfg().PrefixIndexedFields,
tpDispCfgIn.StorDbCfg().Opts, tpDispCfgIn.StorDbCfg().Items)
if err != nil {
log.Fatal(err)
}
storDBOut, err := NewMigratorStorDB(tpDispCfgOut.StorDbCfg().Type,
tpDispCfgOut.StorDbCfg().Host, tpDispCfgOut.StorDbCfg().Port,
tpDispCfgOut.StorDbCfg().Name, tpDispCfgOut.StorDbCfg().User,
tpDispCfgOut.StorDbCfg().Password, tpDispCfgOut.GeneralCfg().DBDataEncoding,
tpDispCfgIn.StorDbCfg().StringIndexedFields, tpDispCfgIn.StorDbCfg().PrefixIndexedFields,
tpDispCfgOut.StorDbCfg().Opts, tpDispCfgOut.StorDbCfg().Items)
if err != nil {
log.Fatal(err)
}
tpDispMigrator, err = NewMigrator(nil, nil, storDBIn, storDBOut, false, false, false, false)
if err != nil {
log.Fatal(err)
}
}
func testTpDispITFlush(t *testing.T) {
if err := tpDispMigrator.storDBIn.StorDB().Flush(
path.Join(tpDispCfgIn.DataFolderPath, "storage",
tpDispCfgIn.StorDbCfg().Type)); err != nil {
t.Error(err)
}
if err := tpDispMigrator.storDBOut.StorDB().Flush(
path.Join(tpDispCfgOut.DataFolderPath, "storage",
tpDispCfgOut.StorDbCfg().Type)); err != nil {
t.Error(err)
}
}
func testTpDispITPopulate(t *testing.T) {
tpDisps = []*utils.TPDispatcherProfile{
{
TPid: "TP1",
Tenant: "cgrates.org",
ID: "Dsp1",
FilterIDs: []string{"*string:Account:1002", "*ai:~*req.AnswerTime:2014-07-29T15:00:00Z"},
Strategy: utils.MetaFirst,
Weight: 10,
},
}
if err := tpDispMigrator.storDBIn.StorDB().SetTPDispatcherProfiles(tpDisps); err != nil {
t.Error("Error when setting TpDispatchers ", err.Error())
}
currentVersion := engine.CurrentStorDBVersions()
err := tpDispMigrator.storDBIn.StorDB().SetVersions(currentVersion, false)
if err != nil {
t.Error("Error when setting version for TpDispatchers ", err.Error())
}
}
func testTpDispITMove(t *testing.T) {
err, _ := tpDispMigrator.Migrate([]string{utils.MetaTpDispatchers})
if err != nil {
t.Error("Error when migrating TpDispatchers ", err.Error())
}
}
func testTpDispITCheckData(t *testing.T) {
result, err := tpDispMigrator.storDBOut.StorDB().GetTPDispatcherProfiles("TP1", "cgrates.org", "Dsp1")
if err != nil {
t.Fatal("Error when getting TpDispatchers ", err.Error())
}
sort.Strings(tpDisps[0].FilterIDs)
sort.Strings(result[0].FilterIDs)
if !reflect.DeepEqual(tpDisps[0], result[0]) {
t.Errorf("Expecting: %+v, received: %+v",
utils.ToJSON(tpDisps[0]), utils.ToJSON(result[0]))
}
result, err = tpDispMigrator.storDBIn.StorDB().GetTPDispatcherProfiles("TP1", "cgrates.org", "Dsp1")
if err != utils.ErrNotFound {
t.Error(err)
}
}

View File

@@ -1,76 +0,0 @@
/*
Real-time Online/Offline Charging System (OCS) for Telecom & ISP environments
Copyright (C) ITsysCOM GmbH
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>
*/
package migrator
import (
"github.com/cgrates/cgrates/engine"
"github.com/cgrates/cgrates/utils"
)
func (m *Migrator) migrateCurrentTPfilters() (err error) {
tpids, err := m.storDBIn.StorDB().GetTpIds(utils.TBLTPFilters)
if err != nil {
return err
}
for _, tpid := range tpids {
ids, err := m.storDBIn.StorDB().GetTpTableIds(tpid, utils.TBLTPFilters,
[]string{"id"}, map[string]string{}, nil)
if err != nil {
return err
}
for _, id := range ids {
fltrs, err := m.storDBIn.StorDB().GetTPFilters(tpid, "", id)
if err != nil {
return err
}
if fltrs == nil || m.dryRun {
continue
}
if err := m.storDBOut.StorDB().SetTPFilters(fltrs); err != nil {
return err
}
for _, fltr := range fltrs {
if err := m.storDBIn.StorDB().RemTpData(utils.TBLTPFilters,
fltr.TPid, map[string]string{"tenant": fltr.Tenant, "id": fltr.ID}); err != nil {
return err
}
}
m.stats[utils.TpFilters]++
}
}
return
}
func (m *Migrator) migrateTPfilters() (err error) {
var vrs engine.Versions
current := engine.CurrentStorDBVersions()
if vrs, err = m.getVersions(utils.TpFilters); err != nil {
return
}
switch vrs[utils.TpFilters] {
case current[utils.TpFilters]:
if m.sameStorDB {
break
}
if err := m.migrateCurrentTPfilters(); err != nil {
return err
}
}
return m.ensureIndexesStorDB(utils.TBLTPFilters)
}

View File

@@ -1,154 +0,0 @@
//go:build integration
// +build integration
/*
Real-time Online/Offline Charging System (OCS) for Telecom & ISP environments
Copyright (C) ITsysCOM GmbH
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>
*/
package migrator
import (
"log"
"path"
"reflect"
"testing"
"github.com/cgrates/birpc/context"
"github.com/cgrates/cgrates/config"
"github.com/cgrates/cgrates/engine"
"github.com/cgrates/cgrates/utils"
)
var (
tpFltrPathIn string
tpFltrPathOut string
tpFltrCfgIn *config.CGRConfig
tpFltrCfgOut *config.CGRConfig
tpFltrMigrator *Migrator
tpFilters []*utils.TPFilterProfile
)
var sTestsTpFltrIT = []func(t *testing.T){
testTpFltrITConnect,
testTpFltrITFlush,
testTpFltrITPopulate,
testTpFltrITMove,
testTpFltrITCheckData,
}
func TestTpFltrMove(t *testing.T) {
for _, stest := range sTestsTpFltrIT {
t.Run("TestTpFltrMove", stest)
}
tpFltrMigrator.Close()
}
func testTpFltrITConnect(t *testing.T) {
var err error
tpFltrPathIn = path.Join(*dataDir, "conf", "samples", "tutmongo")
tpFltrCfgIn, err = config.NewCGRConfigFromPath(context.Background(), tpFltrPathIn)
if err != nil {
t.Fatal(err)
}
tpFltrPathOut = path.Join(*dataDir, "conf", "samples", "tutmysql")
tpFltrCfgOut, err = config.NewCGRConfigFromPath(context.Background(), tpFltrPathOut)
if err != nil {
t.Fatal(err)
}
storDBIn, err := NewMigratorStorDB(tpFltrCfgIn.StorDbCfg().Type,
tpFltrCfgIn.StorDbCfg().Host, tpFltrCfgIn.StorDbCfg().Port,
tpFltrCfgIn.StorDbCfg().Name, tpFltrCfgIn.StorDbCfg().User,
tpFltrCfgIn.StorDbCfg().Password, tpFltrCfgIn.GeneralCfg().DBDataEncoding,
tpFltrCfgOut.StorDbCfg().StringIndexedFields, tpFltrCfgOut.StorDbCfg().PrefixIndexedFields,
tpFltrCfgIn.StorDbCfg().Opts, tpFltrCfgIn.StorDbCfg().Items)
if err != nil {
log.Fatal(err)
}
storDBOut, err := NewMigratorStorDB(tpFltrCfgOut.StorDbCfg().Type,
tpFltrCfgOut.StorDbCfg().Host, tpFltrCfgOut.StorDbCfg().Port,
tpFltrCfgOut.StorDbCfg().Name, tpFltrCfgOut.StorDbCfg().User,
tpFltrCfgOut.StorDbCfg().Password, tpFltrCfgOut.GeneralCfg().DBDataEncoding,
tpFltrCfgOut.StorDbCfg().StringIndexedFields, tpFltrCfgOut.StorDbCfg().PrefixIndexedFields,
tpFltrCfgOut.StorDbCfg().Opts, tpFltrCfgOut.StorDbCfg().Items)
if err != nil {
log.Fatal(err)
}
tpFltrMigrator, err = NewMigrator(nil, nil, storDBIn, storDBOut, false, false, false, false)
if err != nil {
log.Fatal(err)
}
}
func testTpFltrITFlush(t *testing.T) {
if err := tpFltrMigrator.storDBIn.StorDB().Flush(
path.Join(tpFltrCfgIn.DataFolderPath, "storage", tpFltrCfgIn.StorDbCfg().Type)); err != nil {
t.Error(err)
}
if err := tpFltrMigrator.storDBOut.StorDB().Flush(
path.Join(tpFltrCfgOut.DataFolderPath, "storage", tpFltrCfgOut.StorDbCfg().Type)); err != nil {
t.Error(err)
}
}
func testTpFltrITPopulate(t *testing.T) {
tpFilters = []*utils.TPFilterProfile{
{
TPid: "TP1",
Tenant: "cgrates.org",
ID: "Filter",
Filters: []*utils.TPFilter{
{
Type: utils.MetaString,
Element: "Account",
Values: []string{"1001", "1002"},
},
},
},
}
if err := tpFltrMigrator.storDBIn.StorDB().SetTPFilters(tpFilters); err != nil {
t.Error("Error when setting TpFilter ", err.Error())
}
currentVersion := engine.CurrentStorDBVersions()
err := tpFltrMigrator.storDBIn.StorDB().SetVersions(currentVersion, false)
if err != nil {
t.Error("Error when setting version for TpFilter ", err.Error())
}
}
func testTpFltrITMove(t *testing.T) {
err, _ := tpFltrMigrator.Migrate([]string{utils.MetaTpFilters})
if err != nil {
t.Error("Error when migrating TpFilter ", err.Error())
}
}
func testTpFltrITCheckData(t *testing.T) {
result, err := tpFltrMigrator.storDBOut.StorDB().GetTPFilters(
tpFilters[0].TPid, "", tpFilters[0].ID)
if err != nil {
t.Error("Error when getting TpFilter ", err.Error())
}
if !reflect.DeepEqual(tpFilters[0], result[0]) {
t.Errorf("Expecting: %+v, received: %+v", tpFilters[0], result[0])
}
result, err = tpFltrMigrator.storDBIn.StorDB().GetTPFilters(
tpFilters[0].TPid, "", tpFilters[0].ID)
if err != utils.ErrNotFound {
t.Error(err)
}
}

View File

@@ -1,77 +0,0 @@
/*
Real-time Online/Offline Charging System (OCS) for Telecom & ISP environments
Copyright (C) ITsysCOM GmbH
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>
*/
package migrator
import (
"github.com/cgrates/cgrates/engine"
"github.com/cgrates/cgrates/utils"
)
func (m *Migrator) migrateCurrentTPRateProfiles() (err error) {
tpids, err := m.storDBIn.StorDB().GetTpIds(utils.TBLTPRateProfiles)
if err != nil {
return err
}
for _, tpid := range tpids {
ids, err := m.storDBIn.StorDB().GetTpTableIds(tpid, utils.TBLTPRateProfiles,
[]string{"id"}, map[string]string{}, nil)
if err != nil {
return err
}
for _, id := range ids {
rateProfiles, err := m.storDBIn.StorDB().GetTPRateProfiles(tpid, utils.EmptyString, id)
if err != nil {
return err
}
if rateProfiles == nil || m.dryRun {
continue
}
if err := m.storDBOut.StorDB().SetTPRateProfiles(rateProfiles); err != nil {
return err
}
for _, rateProfile := range rateProfiles {
if err := m.storDBIn.StorDB().RemTpData(utils.TBLTPRateProfiles, rateProfile.TPid,
map[string]string{"tenant": rateProfile.Tenant, "id": rateProfile.ID}); err != nil {
return err
}
}
m.stats[utils.TpRateProfiles]++
}
}
return
}
func (m *Migrator) migrateTPRateProfiles() (err error) {
var vrs engine.Versions
current := engine.CurrentStorDBVersions()
if vrs, err = m.getVersions(utils.TpRateProfiles); err != nil {
return err
}
switch vrs[utils.TpRateProfiles] {
case current[utils.TpRateProfiles]:
if m.sameStorDB {
break
}
if err := m.migrateCurrentTPRateProfiles(); err != nil {
return err
}
}
return m.ensureIndexesStorDB(utils.TpRateProfiles)
}

View File

@@ -1,186 +0,0 @@
//go:build integration
// +build integration
/*
Real-time Online/Offline Charging System (OCS) for Telecom & ISP environments
Copyright (C) ITsysCOM GmbH
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>
*/
package migrator
import (
"path"
"reflect"
"testing"
"github.com/cgrates/birpc/context"
"github.com/cgrates/cgrates/engine"
"github.com/cgrates/cgrates/config"
"github.com/cgrates/cgrates/utils"
)
var (
tpRatePrfPathIn string
tpRatePrfPathOut string
tpRatePrfCfgIn *config.CGRConfig
tpRatePrfCfgOut *config.CGRConfig
tpRatePrfMigrator *Migrator
tpRateProfiles []*utils.TPRateProfile
)
var sTestsTPRatePrfIT = []func(t *testing.T){
testTPRateProfileConnect,
testTPRateProfileFlush,
testTPRateProfilePopulate,
testTpRateProfileMove,
testTpRateProfileCheckData,
}
func TestTPRateProfileIT(t *testing.T) {
for _, tests := range sTestsTPRatePrfIT {
t.Run("TestTPRatePrfIT", tests)
}
tpRatePrfMigrator.Close()
}
func testTPRateProfileConnect(t *testing.T) {
var err error
tpRatePrfPathIn := path.Join(*dataDir, "conf", "samples", "tutmongo")
if tpRatePrfCfgIn, err = config.NewCGRConfigFromPath(context.Background(), tpRatePrfPathIn); err != nil {
t.Error(err)
}
tpRatePrfPathOut := path.Join(*dataDir, "conf", "samples", "tutmysql")
if tpRatePrfCfgOut, err = config.NewCGRConfigFromPath(context.Background(), tpRatePrfPathOut); err != nil {
t.Error(err)
}
storDBIn, err := NewMigratorStorDB(tpRatePrfCfgIn.StorDbCfg().Type,
tpRatePrfCfgIn.StorDbCfg().Host, tpRatePrfCfgIn.StorDbCfg().Port,
tpRatePrfCfgIn.StorDbCfg().Name, tpRatePrfCfgIn.StorDbCfg().User,
tpRatePrfCfgIn.StorDbCfg().Password, tpRatePrfCfgIn.GeneralCfg().DBDataEncoding,
tpRatePrfCfgIn.StorDbCfg().StringIndexedFields, tpRatePrfCfgIn.StorDbCfg().PrefixIndexedFields,
tpRatePrfCfgIn.StorDbCfg().Opts, tpRatePrfCfgIn.StorDbCfg().Items)
if err != nil {
t.Error(err)
}
storDBOut, err := NewMigratorStorDB(tpRatePrfCfgOut.StorDbCfg().Type,
tpRatePrfCfgOut.StorDbCfg().Host, tpRatePrfCfgOut.StorDbCfg().Port,
tpRatePrfCfgOut.StorDbCfg().Name, tpRatePrfCfgOut.StorDbCfg().User,
tpRatePrfCfgOut.StorDbCfg().Password, tpRatePrfCfgOut.GeneralCfg().DBDataEncoding,
tpRatePrfCfgOut.StorDbCfg().StringIndexedFields, tpRatePrfCfgOut.StorDbCfg().PrefixIndexedFields,
tpRatePrfCfgOut.StorDbCfg().Opts, tpRatePrfCfgOut.StorDbCfg().Items)
if err != nil {
t.Error(err)
}
tpRatePrfMigrator, err = NewMigrator(nil, nil, storDBIn, storDBOut,
false, false, false, false)
if err != nil {
t.Error(err)
}
}
func testTPRateProfileFlush(t *testing.T) {
if err := tpRatePrfMigrator.storDBIn.StorDB().Flush(
path.Join(tpRatePrfCfgIn.DataFolderPath, "storage", tpRatePrfCfgIn.StorDbCfg().Type)); err != nil {
t.Error(err)
}
if err := tpRatePrfMigrator.storDBOut.StorDB().Flush(
path.Join(tpRatePrfCfgOut.DataFolderPath, "storage", tpRatePrfCfgOut.StorDbCfg().Type)); err != nil {
t.Error(err)
}
}
func testTPRateProfilePopulate(t *testing.T) {
tpRateProfiles = []*utils.TPRateProfile{
{
TPid: "id_RP1",
Tenant: "cgrates.org",
ID: "RP1",
FilterIDs: []string{"*string:~*req.Subject:1001"},
Weights: ";0",
MinCost: 0.1,
MaxCost: 0.6,
MaxCostStrategy: "*free",
Rates: map[string]*utils.TPRate{
"FIRST_GI": {
ID: "FIRST_GI",
FilterIDs: []string{"*gi:~*req.Usage:0"},
Weights: ";0",
IntervalRates: []*utils.TPIntervalRate{
{
RecurrentFee: 0.12,
Unit: "1m",
Increment: "1m",
},
},
Blocker: false,
},
"SECOND_GI": {
ID: "SECOND_GI",
FilterIDs: []string{"*gi:~*req.Usage:1m"},
Weights: ";10",
IntervalRates: []*utils.TPIntervalRate{
{
RecurrentFee: 0.06,
Unit: "1m",
Increment: "1s",
},
},
Blocker: false,
},
},
},
}
//empty in database
if _, err := tpRatePrfMigrator.storDBIn.StorDB().GetTPRateProfiles(tpRateProfiles[0].TPid,
utils.EmptyString, tpRateProfiles[0].ID); err != utils.ErrNotFound {
t.Error(err)
}
if err := tpRatePrfMigrator.storDBIn.StorDB().SetTPRateProfiles(tpRateProfiles); err != nil {
t.Error("Error when setting TpRateProfile ", err.Error())
}
currentVersion := engine.CurrentStorDBVersions()
err := tpRatePrfMigrator.storDBIn.StorDB().SetVersions(currentVersion, false)
if err != nil {
t.Error("Error when setting version for TpRateProfile ", err.Error())
}
}
func testTpRateProfileMove(t *testing.T) {
err, _ := tpRatePrfMigrator.Migrate([]string{utils.MetaTpRateProfiles})
if err != nil {
t.Error("Error when migrating TpRateProfiles", err.Error())
}
}
func testTpRateProfileCheckData(t *testing.T) {
rcv, err := tpRatePrfMigrator.storDBOut.StorDB().GetTPRateProfiles(tpRateProfiles[0].TPid,
utils.EmptyString, tpRateProfiles[0].ID)
if err != nil {
t.Error(err)
}
if !reflect.DeepEqual(rcv[0], tpRateProfiles[0]) {
t.Errorf("Expected %+v, received %+v", tpRateProfiles[0], rcv[0])
}
_, err = tpRatePrfMigrator.storDBIn.StorDB().GetTPRateProfiles(tpRateProfiles[0].TPid,
utils.EmptyString, tpRateProfiles[0].ID)
if err != utils.ErrNotFound {
t.Error(err)
}
}

View File

@@ -1,78 +0,0 @@
/*
Real-time Online/Offline Charging System (OCS) for Telecom & ISP environments
Copyright (C) ITsysCOM GmbH
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>
*/
package migrator
import (
"github.com/cgrates/cgrates/engine"
"github.com/cgrates/cgrates/utils"
)
func (m *Migrator) migrateCurrentTPresources() (err error) {
tpids, err := m.storDBIn.StorDB().GetTpIds(utils.TBLTPResources)
if err != nil {
return err
}
for _, tpid := range tpids {
ids, err := m.storDBIn.StorDB().GetTpTableIds(tpid, utils.TBLTPResources,
[]string{"id"}, map[string]string{}, nil)
if err != nil {
return err
}
for _, id := range ids {
resources, err := m.storDBIn.StorDB().GetTPResources(tpid, "", id)
if err != nil {
return err
}
if resources == nil || m.dryRun {
continue
}
if err := m.storDBOut.StorDB().SetTPResources(resources); err != nil {
return err
}
for _, resource := range resources {
if err := m.storDBIn.StorDB().RemTpData(utils.TBLTPResources, resource.TPid,
map[string]string{"id": resource.ID}); err != nil {
return err
}
}
m.stats[utils.TpResources]++
}
}
return
}
func (m *Migrator) migrateTPresources() (err error) {
var vrs engine.Versions
current := engine.CurrentStorDBVersions()
if vrs, err = m.getVersions(utils.TpResources); err != nil {
return
}
switch vrs[utils.TpResources] {
case current[utils.TpResources]:
if m.sameStorDB {
break
}
if err := m.migrateCurrentTPresources(); err != nil {
return err
}
}
return m.ensureIndexesStorDB(utils.TBLTPResources)
}

View File

@@ -1,160 +0,0 @@
//go:build integration
// +build integration
/*
Real-time Online/Offline Charging System (OCS) for Telecom & ISP environments
Copyright (C) ITsysCOM GmbH
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>
*/
package migrator
import (
"log"
"path"
"reflect"
"sort"
"testing"
"github.com/cgrates/birpc/context"
"github.com/cgrates/cgrates/config"
"github.com/cgrates/cgrates/engine"
"github.com/cgrates/cgrates/utils"
)
var (
tpResPathIn string
tpResPathOut string
tpResCfgIn *config.CGRConfig
tpResCfgOut *config.CGRConfig
tpResMigrator *Migrator
tpResources []*utils.TPResourceProfile
)
var sTestsTpResIT = []func(t *testing.T){
testTpResITConnect,
testTpResITFlush,
testTpResITPopulate,
testTpResITMove,
testTpResITCheckData,
}
func TestTpResMove(t *testing.T) {
for _, stest := range sTestsTpResIT {
t.Run("TestTpResMove", stest)
}
tpResMigrator.Close()
}
func testTpResITConnect(t *testing.T) {
var err error
tpResPathIn = path.Join(*dataDir, "conf", "samples", "tutmongo")
tpResCfgIn, err = config.NewCGRConfigFromPath(context.Background(), tpResPathIn)
if err != nil {
t.Fatal(err)
}
tpResPathOut = path.Join(*dataDir, "conf", "samples", "tutmysql")
tpResCfgOut, err = config.NewCGRConfigFromPath(context.Background(), tpResPathOut)
if err != nil {
t.Fatal(err)
}
storDBIn, err := NewMigratorStorDB(tpResCfgIn.StorDbCfg().Type,
tpResCfgIn.StorDbCfg().Host, tpResCfgIn.StorDbCfg().Port,
tpResCfgIn.StorDbCfg().Name, tpResCfgIn.StorDbCfg().User,
tpResCfgIn.StorDbCfg().Password, tpResCfgIn.GeneralCfg().DBDataEncoding,
tpResCfgIn.StorDbCfg().StringIndexedFields, tpResCfgIn.StorDbCfg().PrefixIndexedFields,
tpResCfgIn.StorDbCfg().Opts, tpResCfgIn.StorDbCfg().Items)
if err != nil {
log.Fatal(err)
}
storDBOut, err := NewMigratorStorDB(tpResCfgOut.StorDbCfg().Type,
tpResCfgOut.StorDbCfg().Host, tpResCfgOut.StorDbCfg().Port,
tpResCfgOut.StorDbCfg().Name, tpResCfgOut.StorDbCfg().User,
tpResCfgOut.StorDbCfg().Password, tpResCfgOut.GeneralCfg().DBDataEncoding,
tpResCfgIn.StorDbCfg().StringIndexedFields, tpResCfgIn.StorDbCfg().PrefixIndexedFields,
tpResCfgOut.StorDbCfg().Opts, tpResCfgOut.StorDbCfg().Items)
if err != nil {
log.Fatal(err)
}
tpResMigrator, err = NewMigrator(nil, nil, storDBIn, storDBOut,
false, false, false, false)
if err != nil {
log.Fatal(err)
}
}
func testTpResITFlush(t *testing.T) {
if err := tpResMigrator.storDBIn.StorDB().Flush(
path.Join(tpResCfgIn.DataFolderPath, "storage", tpResCfgIn.StorDbCfg().Type)); err != nil {
t.Error(err)
}
if err := tpResMigrator.storDBOut.StorDB().Flush(
path.Join(tpResCfgOut.DataFolderPath, "storage", tpResCfgOut.StorDbCfg().Type)); err != nil {
t.Error(err)
}
}
func testTpResITPopulate(t *testing.T) {
tpResources = []*utils.TPResourceProfile{
{
Tenant: "cgrates.org",
TPid: "TPR1",
ID: "ResGroup1",
FilterIDs: []string{"FLTR_1", "*ai:~*req.AnswerTime:2014-07-29T15:00:00Z"},
UsageTTL: "1s",
Limit: "7",
AllocationMessage: "",
Blocker: true,
Stored: true,
Weights: ";20",
ThresholdIDs: []string{"ValOne", "ValTwo"},
},
}
if err := tpResMigrator.storDBIn.StorDB().SetTPResources(tpResources); err != nil {
t.Error("Error when setting TpResources ", err.Error())
}
currentVersion := engine.CurrentStorDBVersions()
err := tpResMigrator.storDBIn.StorDB().SetVersions(currentVersion, false)
if err != nil {
t.Error("Error when setting version for TpResources ", err.Error())
}
}
func testTpResITMove(t *testing.T) {
err, _ := tpResMigrator.Migrate([]string{utils.MetaTpResources})
if err != nil {
t.Error("Error when migrating TpResources ", err.Error())
}
}
func testTpResITCheckData(t *testing.T) {
result, err := tpResMigrator.storDBOut.StorDB().GetTPResources(
tpResources[0].TPid, "", tpResources[0].ID)
if err != nil {
t.Error("Error when getting TpResources ", err.Error())
}
sort.Strings(result[0].ThresholdIDs)
sort.Strings(result[0].FilterIDs)
sort.Strings(tpResources[0].FilterIDs)
if !reflect.DeepEqual(tpResources[0], result[0]) {
t.Errorf("Expecting: %+v, received: %+v", utils.ToJSON(tpResources[0]), utils.ToJSON(result[0]))
}
result, err = tpResMigrator.storDBIn.StorDB().GetTPResources(
tpResources[0].TPid, "", tpResources[0].ID)
if err != utils.ErrNotFound {
t.Error(err)
}
}

View File

@@ -1,78 +0,0 @@
/*
Real-time Online/Offline Charging System (OCS) for Telecom & ISP environments
Copyright (C) ITsysCOM GmbH
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>
*/
package migrator
import (
"github.com/cgrates/cgrates/engine"
"github.com/cgrates/cgrates/utils"
)
func (m *Migrator) migrateCurrentTPRoutes() (err error) {
tpids, err := m.storDBIn.StorDB().GetTpIds(utils.TBLTPRoutes)
if err != nil {
return err
}
for _, tpid := range tpids {
ids, err := m.storDBIn.StorDB().GetTpTableIds(tpid, utils.TBLTPRoutes,
[]string{"id"}, map[string]string{}, nil)
if err != nil {
return err
}
for _, id := range ids {
routes, err := m.storDBIn.StorDB().GetTPRoutes(tpid, "", id)
if err != nil {
return err
}
if routes == nil || m.dryRun {
continue
}
if err := m.storDBOut.StorDB().SetTPRoutes(routes); err != nil {
return err
}
for _, route := range routes {
if err := m.storDBIn.StorDB().RemTpData(utils.TBLTPRoutes, route.TPid,
map[string]string{"tenant": route.Tenant, "id": route.ID}); err != nil {
return err
}
}
m.stats[utils.TpRoutes]++
}
}
return
}
func (m *Migrator) migrateTPRoutes() (err error) {
var vrs engine.Versions
current := engine.CurrentStorDBVersions()
if vrs, err = m.getVersions(utils.TpRoutes); err != nil {
return
}
switch vrs[utils.TpRoutes] {
case current[utils.TpRoutes]:
if m.sameStorDB {
break
}
if err := m.migrateCurrentTPRoutes(); err != nil {
return err
}
}
return m.ensureIndexesStorDB(utils.TBLTPRoutes)
}

View File

@@ -1,168 +0,0 @@
//go:build integration
// +build integration
/*
Real-time Online/Offline Charging System (OCS) for Telecom & ISP environments
Copyright (C) ITsysCOM GmbH
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>
*/
package migrator
import (
"log"
"path"
"reflect"
"sort"
"testing"
"github.com/cgrates/birpc/context"
"github.com/cgrates/cgrates/config"
"github.com/cgrates/cgrates/engine"
"github.com/cgrates/cgrates/utils"
)
var (
tpSplPathIn string
tpSplPathOut string
tpSplCfgIn *config.CGRConfig
tpSplCfgOut *config.CGRConfig
tpSplMigrator *Migrator
tpSuppliers []*utils.TPRouteProfile
)
var sTestsTpSplIT = []func(t *testing.T){
testTpSplITConnect,
testTpSplITFlush,
testTpSplITPopulate,
testTpSplITMove,
testTpSplITCheckData,
}
func TestTpSplMove(t *testing.T) {
for _, stest := range sTestsTpSplIT {
t.Run("TestTpSplMove", stest)
}
tpSplMigrator.Close()
}
func testTpSplITConnect(t *testing.T) {
var err error
tpSplPathIn = path.Join(*dataDir, "conf", "samples", "tutmongo")
tpSplCfgIn, err = config.NewCGRConfigFromPath(context.Background(), tpSplPathIn)
if err != nil {
t.Fatal(err)
}
tpSplPathOut = path.Join(*dataDir, "conf", "samples", "tutmysql")
tpSplCfgOut, err = config.NewCGRConfigFromPath(context.Background(), tpSplPathOut)
if err != nil {
t.Fatal(err)
}
storDBIn, err := NewMigratorStorDB(tpSplCfgIn.StorDbCfg().Type,
tpSplCfgIn.StorDbCfg().Host, tpSplCfgIn.StorDbCfg().Port,
tpSplCfgIn.StorDbCfg().Name, tpSplCfgIn.StorDbCfg().User,
tpSplCfgIn.StorDbCfg().Password, tpSplCfgIn.GeneralCfg().DBDataEncoding,
tpSplCfgIn.StorDbCfg().StringIndexedFields, tpSplCfgIn.StorDbCfg().PrefixIndexedFields,
tpSplCfgIn.StorDbCfg().Opts, tpSplCfgIn.StorDbCfg().Items)
if err != nil {
log.Fatal(err)
}
storDBOut, err := NewMigratorStorDB(tpSplCfgOut.StorDbCfg().Type,
tpSplCfgOut.StorDbCfg().Host, tpSplCfgOut.StorDbCfg().Port,
tpSplCfgOut.StorDbCfg().Name, tpSplCfgOut.StorDbCfg().User,
tpSplCfgOut.StorDbCfg().Password, tpSplCfgOut.GeneralCfg().DBDataEncoding,
tpSplCfgIn.StorDbCfg().StringIndexedFields, tpSplCfgIn.StorDbCfg().PrefixIndexedFields,
tpSplCfgOut.StorDbCfg().Opts, tpSplCfgOut.StorDbCfg().Items)
if err != nil {
log.Fatal(err)
}
tpSplMigrator, err = NewMigrator(nil, nil, storDBIn, storDBOut, false, false, false, false)
if err != nil {
log.Fatal(err)
}
}
func testTpSplITFlush(t *testing.T) {
if err := tpSplMigrator.storDBIn.StorDB().Flush(
path.Join(tpSplCfgIn.DataFolderPath, "storage", tpSplCfgIn.StorDbCfg().Type)); err != nil {
t.Error(err)
}
if err := tpSplMigrator.storDBOut.StorDB().Flush(
path.Join(tpSplCfgOut.DataFolderPath, "storage", tpSplCfgOut.StorDbCfg().Type)); err != nil {
t.Error(err)
}
}
func testTpSplITPopulate(t *testing.T) {
tpSuppliers = []*utils.TPRouteProfile{
{
TPid: "TP1",
Tenant: "cgrates.org",
ID: "SUPL_1",
FilterIDs: []string{"FLTR_ACNT_dan", "FLTR_DST_DE"},
Sorting: "*lowest_cost",
SortingParameters: []string{},
Routes: []*utils.TPRoute{
{
ID: "supplier1",
FilterIDs: []string{"FLTR_1"},
AccountIDs: []string{"Acc1", "Acc2"},
RateProfileIDs: []string{"RPL_1"},
ResourceIDs: []string{"ResGroup1"},
StatIDs: []string{"Stat1"},
// Weights: 10,
Blocker: false,
RouteParameters: "SortingParam1",
},
},
// Weights: 20,
},
}
if err := tpSplMigrator.storDBIn.StorDB().SetTPRoutes(tpSuppliers); err != nil {
t.Error("Error when setting TpSuppliers ", err.Error())
}
currentVersion := engine.CurrentStorDBVersions()
err := tpSplMigrator.storDBIn.StorDB().SetVersions(currentVersion, false)
if err != nil {
t.Error("Error when setting version for TpSuppliers ", err.Error())
}
}
func testTpSplITMove(t *testing.T) {
err, _ := tpSplMigrator.Migrate([]string{utils.MetaTpRoutes})
if err != nil {
t.Error("Error when migrating TpSuppliers ", err.Error())
}
}
func testTpSplITCheckData(t *testing.T) {
result, err := tpSplMigrator.storDBOut.StorDB().GetTPRoutes(
tpSuppliers[0].TPid, "", tpSuppliers[0].ID)
if err != nil {
t.Error("Error when getting TpSuppliers ", err.Error())
}
tpSuppliers[0].SortingParameters = nil // because of converting and empty string into a slice
sort.Strings(result[0].FilterIDs)
sort.Strings(tpSuppliers[0].FilterIDs)
if !reflect.DeepEqual(tpSuppliers[0], result[0]) {
t.Errorf("Expecting: %+v, received: %+v", utils.ToJSON(tpSuppliers[0]), utils.ToJSON(result[0]))
}
result, err = tpSplMigrator.storDBIn.StorDB().GetTPRoutes(
tpSuppliers[0].TPid, "", tpSuppliers[0].ID)
if err != utils.ErrNotFound {
t.Error(err)
}
}

View File

@@ -1,77 +0,0 @@
/*
Real-time Online/Offline Charging System (OCS) for Telecom & ISP environments
Copyright (C) ITsysCOM GmbH
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>
*/
package migrator
import (
"github.com/cgrates/cgrates/engine"
"github.com/cgrates/cgrates/utils"
)
func (m *Migrator) migrateCurrentTPstats() (err error) {
tpids, err := m.storDBIn.StorDB().GetTpIds(utils.TBLTPStats)
if err != nil {
return err
}
for _, tpid := range tpids {
ids, err := m.storDBIn.StorDB().GetTpTableIds(tpid, utils.TBLTPStats,
[]string{"id"}, map[string]string{}, nil)
if err != nil {
return err
}
for _, id := range ids {
stats, err := m.storDBIn.StorDB().GetTPStats(tpid, "", id)
if err != nil {
return err
}
if stats == nil || m.dryRun {
continue
}
if err := m.storDBOut.StorDB().SetTPStats(stats); err != nil {
return err
}
for _, stat := range stats {
if err := m.storDBIn.StorDB().RemTpData(utils.TBLTPStats, stat.TPid,
map[string]string{"id": stat.ID}); err != nil {
return err
}
}
m.stats[utils.TpStats]++
}
}
return
}
func (m *Migrator) migrateTPstats() (err error) {
var vrs engine.Versions
current := engine.CurrentStorDBVersions()
if vrs, err = m.getVersions(utils.TpStats); err != nil {
return
}
switch vrs[utils.TpStats] {
case current[utils.TpStats]:
if m.sameStorDB {
break
}
if err := m.migrateCurrentTPstats(); err != nil {
return err
}
}
return m.ensureIndexesStorDB(utils.TBLTPStats)
}

View File

@@ -1,164 +0,0 @@
//go:build integration
// +build integration
/*
Real-time Online/Offline Charging System (OCS) for Telecom & ISP environments
Copyright (C) ITsysCOM GmbH
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>
*/
package migrator
import (
"log"
"path"
"reflect"
"sort"
"testing"
"github.com/cgrates/birpc/context"
"github.com/cgrates/cgrates/config"
"github.com/cgrates/cgrates/engine"
"github.com/cgrates/cgrates/utils"
)
var (
tpStatsPathIn string
tpStatsPathOut string
tpStatsCfgIn *config.CGRConfig
tpStatsCfgOut *config.CGRConfig
tpStatsMigrator *Migrator
tpStats []*utils.TPStatProfile
)
var sTestsTpStatsIT = []func(t *testing.T){
testTpStatsITConnect,
testTpStatsITFlush,
testTpStatsITPopulate,
testTpStatsITMove,
testTpStatsITCheckData,
}
func TestTpStatsMove(t *testing.T) {
for _, stest := range sTestsTpStatsIT {
t.Run("TestTpStatsMove", stest)
}
tpStatsMigrator.Close()
}
func testTpStatsITConnect(t *testing.T) {
var err error
tpStatsPathIn = path.Join(*dataDir, "conf", "samples", "tutmongo")
tpStatsCfgIn, err = config.NewCGRConfigFromPath(context.Background(), tpStatsPathIn)
if err != nil {
t.Fatal(err)
}
tpStatsPathOut = path.Join(*dataDir, "conf", "samples", "tutmysql")
tpStatsCfgOut, err = config.NewCGRConfigFromPath(context.Background(), tpStatsPathOut)
if err != nil {
t.Fatal(err)
}
storDBIn, err := NewMigratorStorDB(tpStatsCfgIn.StorDbCfg().Type,
tpStatsCfgIn.StorDbCfg().Host, tpStatsCfgIn.StorDbCfg().Port,
tpStatsCfgIn.StorDbCfg().Name, tpStatsCfgIn.StorDbCfg().User,
tpStatsCfgIn.StorDbCfg().Password, tpStatsCfgIn.GeneralCfg().DBDataEncoding,
tpStatsCfgIn.StorDbCfg().StringIndexedFields, tpStatsCfgIn.StorDbCfg().PrefixIndexedFields,
tpStatsCfgIn.StorDbCfg().Opts, tpStatsCfgIn.StorDbCfg().Items)
if err != nil {
log.Fatal(err)
}
storDBOut, err := NewMigratorStorDB(tpStatsCfgOut.StorDbCfg().Type,
tpStatsCfgOut.StorDbCfg().Host, tpStatsCfgOut.StorDbCfg().Port,
tpStatsCfgOut.StorDbCfg().Name, tpStatsCfgOut.StorDbCfg().User,
tpStatsCfgOut.StorDbCfg().Password, tpStatsCfgOut.GeneralCfg().DBDataEncoding,
tpStatsCfgIn.StorDbCfg().StringIndexedFields, tpStatsCfgIn.StorDbCfg().PrefixIndexedFields,
tpStatsCfgOut.StorDbCfg().Opts, tpStatsCfgOut.StorDbCfg().Items)
if err != nil {
log.Fatal(err)
}
tpStatsMigrator, err = NewMigrator(nil, nil, storDBIn, storDBOut, false, false, false, false)
if err != nil {
log.Fatal(err)
}
}
func testTpStatsITFlush(t *testing.T) {
if err := tpStatsMigrator.storDBIn.StorDB().Flush(
path.Join(tpStatsCfgIn.DataFolderPath, "storage", tpStatsCfgIn.StorDbCfg().Type)); err != nil {
t.Error(err)
}
if err := tpStatsMigrator.storDBOut.StorDB().Flush(
path.Join(tpStatsCfgOut.DataFolderPath, "storage", tpStatsCfgOut.StorDbCfg().Type)); err != nil {
t.Error(err)
}
}
func testTpStatsITPopulate(t *testing.T) {
tpStats = []*utils.TPStatProfile{
{
Tenant: "cgrates.org",
TPid: "TPS1",
ID: "Stat1",
FilterIDs: []string{"FLTR_1", "*ai:~*req.AnswerTime:2014-07-29T15:00:00Z"},
TTL: "1",
Metrics: []*utils.MetricWithFilters{
&utils.MetricWithFilters{
MetricID: "*sum#Param1",
},
},
Blocker: false,
Stored: false,
Weights: ";20",
MinItems: 1,
ThresholdIDs: []string{"ThreshValueTwo"},
},
}
if err := tpStatsMigrator.storDBIn.StorDB().SetTPStats(tpStats); err != nil {
t.Error("Error when setting TpStat ", err.Error())
}
currentVersion := engine.CurrentStorDBVersions()
err := tpStatsMigrator.storDBIn.StorDB().SetVersions(currentVersion, false)
if err != nil {
t.Error("Error when setting version for TpStat ", err.Error())
}
}
func testTpStatsITMove(t *testing.T) {
err, _ := tpStatsMigrator.Migrate([]string{utils.MetaTpStats})
if err != nil {
t.Error("Error when migrating TpStat ", err.Error())
}
}
func testTpStatsITCheckData(t *testing.T) {
result, err := tpStatsMigrator.storDBOut.StorDB().GetTPStats(
tpStats[0].TPid, "", tpStats[0].ID)
if err != nil {
t.Error("Error when getting TpStat ", err.Error())
}
tpStats[0].Metrics[0].MetricID = "*sum#Param1" //add parametrics to metricID to use multiple parameters for same metric
sort.Strings(tpStats[0].FilterIDs)
sort.Strings(result[0].FilterIDs)
if !reflect.DeepEqual(tpStats[0], result[0]) {
t.Errorf("Expecting: %+v, received: %+v",
utils.ToJSON(tpStats[0]), utils.ToJSON(result[0]))
}
result, err = tpStatsMigrator.storDBIn.StorDB().GetTPStats(
tpStats[0].TPid, "", tpStats[0].ID)
if err != utils.ErrNotFound {
t.Error(err)
}
}

View File

@@ -1,77 +0,0 @@
/*
Real-time Online/Offline Charging System (OCS) for Telecom & ISP environments
Copyright (C) ITsysCOM GmbH
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>
*/
package migrator
import (
"github.com/cgrates/cgrates/engine"
"github.com/cgrates/cgrates/utils"
)
func (m *Migrator) migrateCurrentTPthresholds() (err error) {
tpids, err := m.storDBIn.StorDB().GetTpIds(utils.TBLTPThresholds)
if err != nil {
return err
}
for _, tpid := range tpids {
ids, err := m.storDBIn.StorDB().GetTpTableIds(tpid, utils.TBLTPThresholds,
[]string{"id"}, map[string]string{}, nil)
if err != nil {
return err
}
for _, id := range ids {
thresholds, err := m.storDBIn.StorDB().GetTPThresholds(tpid, "", id)
if err != nil {
return err
}
if thresholds == nil || m.dryRun {
continue
}
if err := m.storDBOut.StorDB().SetTPThresholds(thresholds); err != nil {
return err
}
for _, threshold := range thresholds {
if err := m.storDBIn.StorDB().RemTpData(utils.TBLTPThresholds, threshold.TPid,
map[string]string{"tenant": threshold.Tenant, "id": threshold.ID}); err != nil {
return err
}
}
m.stats[utils.TpThresholds]++
}
}
return
}
func (m *Migrator) migrateTPthresholds() (err error) {
var vrs engine.Versions
current := engine.CurrentStorDBVersions()
if vrs, err = m.getVersions(utils.TpThresholds); err != nil {
return
}
switch vrs[utils.TpThresholds] {
case current[utils.TpThresholds]:
if m.sameStorDB {
break
}
if err := m.migrateCurrentTPthresholds(); err != nil {
return err
}
}
return m.ensureIndexesStorDB(utils.TBLTPThresholds)
}

View File

@@ -1,158 +0,0 @@
//go:build integration
// +build integration
/*
Real-time Online/Offline Charging System (OCS) for Telecom & ISP environments
Copyright (C) ITsysCOM GmbH
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>
*/
package migrator
import (
"log"
"path"
"reflect"
"sort"
"testing"
"github.com/cgrates/birpc/context"
"github.com/cgrates/cgrates/config"
"github.com/cgrates/cgrates/engine"
"github.com/cgrates/cgrates/utils"
)
var (
tpTresPathIn string
tpTresPathOut string
tpTresCfgIn *config.CGRConfig
tpTresCfgOut *config.CGRConfig
tpTresMigrator *Migrator
tpThresholds []*utils.TPThresholdProfile
)
var sTestsTpTresIT = []func(t *testing.T){
testTpTresITConnect,
testTpTresITFlush,
testTpTresITPopulate,
testTpTresITMove,
testTpTresITCheckData,
}
func TestTpTresMove(t *testing.T) {
for _, stest := range sTestsTpTresIT {
t.Run("TestTpTresMove", stest)
}
tpTresMigrator.Close()
}
func testTpTresITConnect(t *testing.T) {
var err error
tpTresPathIn = path.Join(*dataDir, "conf", "samples", "tutmongo")
tpTresCfgIn, err = config.NewCGRConfigFromPath(context.Background(), tpTresPathIn)
if err != nil {
t.Fatal(err)
}
tpTresPathOut = path.Join(*dataDir, "conf", "samples", "tutmysql")
tpTresCfgOut, err = config.NewCGRConfigFromPath(context.Background(), tpTresPathOut)
if err != nil {
t.Fatal(err)
}
storDBIn, err := NewMigratorStorDB(tpTresCfgIn.StorDbCfg().Type,
tpTresCfgIn.StorDbCfg().Host, tpTresCfgIn.StorDbCfg().Port,
tpTresCfgIn.StorDbCfg().Name, tpTresCfgIn.StorDbCfg().User,
tpTresCfgIn.StorDbCfg().Password, tpTresCfgIn.GeneralCfg().DBDataEncoding,
tpTresCfgIn.StorDbCfg().StringIndexedFields, tpTresCfgIn.StorDbCfg().PrefixIndexedFields,
tpTresCfgIn.StorDbCfg().Opts, tpTresCfgIn.StorDbCfg().Items)
if err != nil {
log.Fatal(err)
}
storDBOut, err := NewMigratorStorDB(tpTresCfgOut.StorDbCfg().Type,
tpTresCfgOut.StorDbCfg().Host, tpTresCfgOut.StorDbCfg().Port,
tpTresCfgOut.StorDbCfg().Name, tpTresCfgOut.StorDbCfg().User,
tpTresCfgOut.StorDbCfg().Password, tpTresCfgOut.GeneralCfg().DBDataEncoding,
tpTresCfgIn.StorDbCfg().StringIndexedFields, tpTresCfgIn.StorDbCfg().PrefixIndexedFields,
tpTresCfgOut.StorDbCfg().Opts, tpTresCfgOut.StorDbCfg().Items)
if err != nil {
log.Fatal(err)
}
tpTresMigrator, err = NewMigrator(nil, nil, storDBIn, storDBOut, false, false, false, false)
if err != nil {
log.Fatal(err)
}
}
func testTpTresITFlush(t *testing.T) {
if err := tpTresMigrator.storDBIn.StorDB().Flush(
path.Join(tpTresCfgIn.DataFolderPath, "storage", tpTresCfgIn.StorDbCfg().Type)); err != nil {
t.Error(err)
}
if err := tpTresMigrator.storDBOut.StorDB().Flush(
path.Join(tpTresCfgOut.DataFolderPath, "storage", tpTresCfgOut.StorDbCfg().Type)); err != nil {
t.Error(err)
}
}
func testTpTresITPopulate(t *testing.T) {
tpThresholds = []*utils.TPThresholdProfile{
{
TPid: "TH1",
Tenant: "cgrates.org",
ID: "Threhold",
FilterIDs: []string{"FLTR_1", "FLTR_2", "*ai:~*req.AnswerTime:2014-07-29T15:00:00Z"},
MaxHits: -1,
MinSleep: "1s",
Blocker: true,
Weights: ";10",
ActionProfileIDs: []string{"Thresh1", "Thresh2"},
Async: true,
},
}
if err := tpTresMigrator.storDBIn.StorDB().SetTPThresholds(tpThresholds); err != nil {
t.Error("Error when setting TpThresholds ", err.Error())
}
currentVersion := engine.CurrentStorDBVersions()
err := tpTresMigrator.storDBIn.StorDB().SetVersions(currentVersion, false)
if err != nil {
t.Error("Error when setting version for TpThresholds ", err.Error())
}
}
func testTpTresITMove(t *testing.T) {
err, _ := tpTresMigrator.Migrate([]string{utils.MetaTpThresholds})
if err != nil {
t.Error("Error when migrating TpThresholds ", err.Error())
}
}
func testTpTresITCheckData(t *testing.T) {
result, err := tpTresMigrator.storDBOut.StorDB().GetTPThresholds(
tpThresholds[0].TPid, "", tpThresholds[0].ID)
if err != nil {
t.Error("Error when getting TpThresholds ", err.Error())
}
sort.Strings(result[0].FilterIDs)
sort.Strings(tpThresholds[0].FilterIDs)
sort.Strings(result[0].ActionProfileIDs)
if !reflect.DeepEqual(tpThresholds[0], result[0]) {
t.Errorf("Expecting: %+v, received: %+v", utils.ToJSON(tpThresholds[0]), utils.ToJSON(result[0]))
}
result, err = tpTresMigrator.storDBIn.StorDB().GetTPThresholds(
tpThresholds[0].TPid, "", tpThresholds[0].ID)
if err != utils.ErrNotFound {
t.Error(err)
}
}

View File

@@ -83,18 +83,8 @@ func testVrsITConnect(t *testing.T) {
if err != nil {
t.Fatal(err)
}
storDBOut, err := NewMigratorStorDB(vrsCfg.StorDbCfg().Type,
vrsCfg.StorDbCfg().Host, vrsCfg.StorDbCfg().Port,
vrsCfg.StorDbCfg().Name, vrsCfg.StorDbCfg().User,
vrsCfg.StorDbCfg().Password, vrsCfg.GeneralCfg().DBDataEncoding,
vrsCfg.StorDbCfg().StringIndexedFields, vrsCfg.StorDbCfg().PrefixIndexedFields,
vrsCfg.StorDbCfg().Opts, vrsCfg.StorDbCfg().Items)
if err != nil {
t.Error(err)
}
vrsMigrator, err = NewMigrator(nil, dataDBOut, nil, storDBOut,
false, false, false, vrsSameOutDB)
vrsMigrator, err = NewMigrator(nil, dataDBOut,
false, false)
if err != nil {
t.Fatal(err)
}
@@ -102,14 +92,9 @@ func testVrsITConnect(t *testing.T) {
func testVrsITFlush(t *testing.T) {
vrsMigrator.dmOut.DataManager().DataDB().Flush("")
vrsMigrator.storDBOut.StorDB().Flush((path.Join(vrsCfg.DataFolderPath, "storage",
vrsCfg.StorDbCfg().Type)))
if vrs, err := vrsMigrator.dmOut.DataManager().DataDB().GetVersions(""); err == nil || err.Error() != utils.ErrNotFound.Error() {
t.Errorf("Expected err=%s received err=%v and rply=%s", utils.ErrNotFound.Error(), err, utils.ToJSON(vrs))
}
if vrs, err := vrsMigrator.storDBOut.StorDB().GetVersions(""); err == nil || err.Error() != utils.ErrNotFound.Error() {
t.Errorf("Expected err=%s received err=%v and rply=%s", utils.ErrNotFound.Error(), err, utils.ToJSON(vrs))
}
}
func testVrsITMigrate(t *testing.T) {
@@ -131,13 +116,6 @@ func testVrsITMigrate(t *testing.T) {
} else if !reflect.DeepEqual(expVrs, vrs) {
t.Errorf("Expected %s received %s", utils.ToJSON(expVrs), utils.ToJSON(vrs))
}
expVrs = engine.CurrentStorDBVersions()
if vrs, err := vrsMigrator.storDBOut.StorDB().GetVersions(""); err != nil {
t.Error(err)
} else if !reflect.DeepEqual(expVrs, vrs) {
t.Errorf("Expected %s received %s", utils.ToJSON(expVrs), utils.ToJSON(vrs))
}
}
currentVersion := engine.Versions{utils.Attributes: 0}
@@ -145,10 +123,6 @@ func testVrsITMigrate(t *testing.T) {
if err != nil {
t.Error("Error when setting version ", err.Error())
}
err = vrsMigrator.storDBOut.StorDB().SetVersions(currentVersion, false)
if err != nil {
t.Error("Error when setting version ", err.Error())
}
vrsMigrator.Migrate([]string{utils.MetaSetVersions})
if vrsSameOutDB {
@@ -166,11 +140,5 @@ func testVrsITMigrate(t *testing.T) {
t.Errorf("Expected %s received %s", utils.ToJSON(expVrs), utils.ToJSON(vrs))
}
expVrs = engine.CurrentStorDBVersions()
if vrs, err := vrsMigrator.storDBOut.StorDB().GetVersions(""); err != nil {
t.Error(err)
} else if !reflect.DeepEqual(expVrs, vrs) {
t.Errorf("Expected %s received %s", utils.ToJSON(expVrs), utils.ToJSON(vrs))
}
}
}