From c6947dbb28321852a56e738ab7f810b60c85ce19 Mon Sep 17 00:00:00 2001 From: TeoV Date: Wed, 29 Nov 2017 19:13:38 +0200 Subject: [PATCH] Add migrate TPSuppliers from one db to another --- engine/onstor_it_test.go | 4 +- migrator/migrator.go | 4 +- migrator/migrator_it_test.go | 71 ++++++++++++++++++++---------------- 3 files changed, 43 insertions(+), 36 deletions(-) diff --git a/engine/onstor_it_test.go b/engine/onstor_it_test.go index d8d2295dd..1e5ffc1df 100644 --- a/engine/onstor_it_test.go +++ b/engine/onstor_it_test.go @@ -101,7 +101,7 @@ var sTestsOnStorIT = []func(t *testing.T){ testOnStorITCRUDThresholdProfile, testOnStorITCRUDThreshold, testOnStorITCRUDFilter, - testOnStorITCRUDLCRProfile, + testOnStorITCRUDSupplierProfile, } func TestOnStorITRedisConnect(t *testing.T) { @@ -2400,7 +2400,7 @@ func testOnStorITCRUDFilter(t *testing.T) { } } -func testOnStorITCRUDLCRProfile(t *testing.T) { +func testOnStorITCRUDSupplierProfile(t *testing.T) { splProfile := &SupplierProfile{ Tenant: "cgrates.org", ID: "SPRF_1", diff --git a/migrator/migrator.go b/migrator/migrator.go index d65567942..e98bef1c5 100755 --- a/migrator/migrator.go +++ b/migrator/migrator.go @@ -131,8 +131,6 @@ func (m *Migrator) Migrate(taskIDs []string) (err error, stats map[string]int) { err = m.migrateStats() case utils.MetaThresholds: err = m.migrateThresholds() - case utils.MetaSuppliers: - err = m.migrateSupplierProfiles() //only Move case utils.MetaRatingPlans: err = m.migrateRatingPlans() @@ -162,6 +160,8 @@ func (m *Migrator) Migrate(taskIDs []string) (err error, stats map[string]int) { err = m.migrateSubscribers() case utils.MetaDerivedChargersV: err = m.migrateDerivedChargers() + case utils.MetaSuppliers: + err = m.migrateSupplierProfiles() //TPS case utils.MetaTpRatingPlans: err = m.migrateTPratingplans() diff --git a/migrator/migrator_it_test.go b/migrator/migrator_it_test.go index 16bc065c3..2d9833113 100644 --- a/migrator/migrator_it_test.go +++ b/migrator/migrator_it_test.go @@ -40,13 +40,16 @@ var ( // subtests to be executed for each migrator var sTestsITMigrator = []func(t *testing.T){ testFlush, - testMigratorAccounts, - testMigratorActionPlans, - testMigratorActionTriggers, - testMigratorActions, - testMigratorSharedGroups, - testMigratorStats, - testMigratorTPRatingProfile, + /* + testMigratorAccounts, + testMigratorActionPlans, + testMigratorActionTriggers, + testMigratorActions, + testMigratorSharedGroups, + testMigratorStats, + testMigratorTPRatingProfile, + */ + testMigratorTPSuppliers, testFlush, } @@ -1047,32 +1050,36 @@ func testMigratorTPRatingProfile(t *testing.T) { } func testMigratorTPSuppliers(t *testing.T) { - tpSplPr := &utils.TPSupplier{ - TPid: "TP1", - Tenant: "cgrates.org", - ID: "SUPL_1", - FilterIDs: []string{"FLTR_ACNT_dan"}, - ActivationInterval: &utils.TPActivationInterval{ - ActivationTime: "2014-07-29T15:00:00Z", - ExpiryTime: "", - }, - Sorting: "*lowest_cost", - SortingParams: []string{}, - Suppliers: []*utils.TPRequestSupplier{ - &utils.TPRequestSupplier{ - ID: "supplier1", - FilterIDs: []string{"FLTR_1"}, - RatingPlanIDs: []string{"RPL_1"}, - ResourceIDs: []string{"ResGroup1"}, - StatIDs: []string{"Stat1"}, + tpSplPr := []*utils.TPSupplier{ + &utils.TPSupplier{ + TPid: "SupplierTPID12", + Tenant: "cgrates.org", + ID: "SUPL_1", + FilterIDs: []string{"FLTR_ACNT_dan"}, + ActivationInterval: &utils.TPActivationInterval{ + ActivationTime: "2014-07-29T15:00:00Z", + ExpiryTime: "", }, + Sorting: "*lowest_cost", + SortingParams: []string{}, + Suppliers: []*utils.TPRequestSupplier{ + &utils.TPRequestSupplier{ + ID: "supplier1", + AccountIDs: []string{"Account1"}, + FilterIDs: []string{"FLTR_1"}, + RatingPlanIDs: []string{"RPL_1"}, + ResourceIDs: []string{"ResGroup1"}, + StatIDs: []string{"Stat1"}, + Weight: 10, + }, + }, + Blocker: false, + Weight: 20, }, - Blocker: false, - Weight: 20, } switch dbtype { case Move: - if err := mig.InStorDB().SetTPSuppliers([]*utils.TPSupplier{tpSplPr}); err != nil { + if err := mig.InStorDB().SetTPSuppliers(tpSplPr); err != nil { t.Error("Error when setting Stats ", err.Error()) } currentVersion := engine.CurrentDataDBVersions() @@ -1084,12 +1091,12 @@ func testMigratorTPSuppliers(t *testing.T) { if err != nil { t.Error("Error when migrating Stats ", err.Error()) } - result, err := mig.OutStorDB().GetTPSuppliers(tpSplPr.TPid, tpSplPr.ID) + result, err := mig.OutStorDB().GetTPSuppliers(tpSplPr[0].TPid, tpSplPr[0].ID) if err != nil { - t.Error("Error when getting Stats ", err.Error()) + t.Error("Error when getting TPSupplier ", err.Error()) } - if !reflect.DeepEqual(tpSplPr, result[0]) { - t.Errorf("Expecting: %+v, received: %+v", tpSplPr, result[0]) + if !reflect.DeepEqual(tpSplPr, result) { + t.Errorf("Expecting: %+v, received: %+v", tpSplPr, result) } } }