diff --git a/engine/version.go b/engine/version.go
index 69e24badc..23b4f4232 100644
--- a/engine/version.go
+++ b/engine/version.go
@@ -117,6 +117,7 @@ func CurrentDataDBVersions() Versions {
utils.ActionPlans: 2,
utils.SharedGroups: 2,
utils.Thresholds: 2,
+ utils.Suppliers: 1,
utils.Timing: 1,
utils.RQF: 1,
utils.Resource: 1,
@@ -147,6 +148,7 @@ func CurrentStorDBVersions() Versions {
utils.TpActions: 1,
utils.TpDerivedCharges: 1,
utils.TpThresholds: 1,
+ utils.TpSuppliers: 1,
utils.TpStats: 1,
utils.TpSharedGroups: 1,
utils.TpRatingProfiles: 1,
diff --git a/migrator/migrator.go b/migrator/migrator.go
index a4d290c8a..d65567942 100755
--- a/migrator/migrator.go
+++ b/migrator/migrator.go
@@ -131,6 +131,8 @@ 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()
@@ -181,6 +183,8 @@ func (m *Migrator) Migrate(taskIDs []string) (err error, stats map[string]int) {
err = m.migrateTPderivedchargers()
case utils.MetaTpThresholds:
err = m.migrateTPthresholds()
+ case utils.MetaTpSuppliers:
+ err = m.migrateTPSuppliers()
case utils.MetaTpStats:
err = m.migrateTPstats()
case utils.MetaTpSharedGroups:
@@ -226,6 +230,9 @@ func (m *Migrator) Migrate(taskIDs []string) (err error, stats map[string]int) {
if err := m.migrateThresholds(); err != nil {
log.Print("ERROR: ", utils.MetaThresholds, " ", err)
}
+ if err := m.migrateSupplierProfiles(); err != nil {
+ log.Print("ERROR: ", utils.MetaSuppliers, " ", err)
+ }
if err := m.migrateRatingPlans(); err != nil {
log.Print("ERROR: ", utils.MetaRatingPlans, " ", err)
}
@@ -301,6 +308,9 @@ func (m *Migrator) Migrate(taskIDs []string) (err error, stats map[string]int) {
if err := m.migrateTPthresholds(); err != nil {
log.Print("ERROR: ", utils.MetaTpThresholds, " ", err)
}
+ if err := m.migrateTPSuppliers(); err != nil {
+ log.Print("ERROR: ", utils.MetaTpSuppliers, " ", err)
+ }
if err := m.migrateTPstats(); err != nil {
log.Print("ERROR: ", utils.MetaTpStats, " ", err)
}
diff --git a/migrator/migrator_it_test.go b/migrator/migrator_it_test.go
index c19eb1e28..16bc065c3 100644
--- a/migrator/migrator_it_test.go
+++ b/migrator/migrator_it_test.go
@@ -1045,3 +1045,51 @@ 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"},
+ },
+ },
+ Blocker: false,
+ Weight: 20,
+ }
+ switch dbtype {
+ case Move:
+ if err := mig.InStorDB().SetTPSuppliers([]*utils.TPSupplier{tpSplPr}); 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.MetaTpSuppliers})
+ if err != nil {
+ t.Error("Error when migrating Stats ", err.Error())
+ }
+ result, err := mig.OutStorDB().GetTPSuppliers(tpSplPr.TPid, tpSplPr.ID)
+ if err != nil {
+ t.Error("Error when getting Stats ", err.Error())
+ }
+ if !reflect.DeepEqual(tpSplPr, result[0]) {
+ t.Errorf("Expecting: %+v, received: %+v", tpSplPr, result[0])
+ }
+ }
+}
diff --git a/migrator/suppliers.go b/migrator/suppliers.go
new file mode 100644
index 000000000..0cc9009a6
--- /dev/null
+++ b/migrator/suppliers.go
@@ -0,0 +1,81 @@
+/*
+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) migrateCurrentSupplierProfile() (err error) {
+ var ids []string
+ tenant := config.CgrConfig().DefaultTenant
+ ids, err = m.dmIN.DataDB().GetKeysForPrefix(utils.SupplierProfilePrefix)
+ if err != nil {
+ return err
+ }
+ for _, id := range ids {
+ idg := strings.TrimPrefix(id, utils.SupplierProfilePrefix)
+ splp, err := m.dmIN.GetSupplierProfile(tenant, idg, true, utils.NonTransactional)
+ if err != nil {
+ return err
+ }
+ if splp != nil {
+ if m.dryRun != true {
+ if err := m.dmOut.SetSupplierProfile(splp); err != nil {
+ return err
+ }
+ m.stats[utils.Suppliers] += 1
+ }
+ }
+ }
+ return
+}
+
+func (m *Migrator) migrateSupplierProfiles() (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.Suppliers] {
+ case current[utils.Suppliers]:
+ if m.sameDataDB {
+ return
+ }
+ if err := m.migrateCurrentSupplierProfile(); err != nil {
+ return err
+ }
+ return
+ }
+ return
+}
diff --git a/migrator/tp_suppliers.go b/migrator/tp_suppliers.go
new file mode 100644
index 000000000..2554c7077
--- /dev/null
+++ b/migrator/tp_suppliers.go
@@ -0,0 +1,84 @@
+/*
+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) migrateCurrentTPSuppliers() (err error) {
+ tpids, err := m.InStorDB().GetTpIds(utils.TBLTPSuppliers)
+ if err != nil {
+ return err
+ }
+
+ for _, tpid := range tpids {
+ ids, err := m.InStorDB().GetTpTableIds(tpid, utils.TBLTPSuppliers, utils.TPDistinctIds{}, map[string]string{}, nil)
+ if err != nil {
+ return err
+ }
+ for _, id := range ids {
+
+ dest, err := m.InStorDB().GetTPSuppliers(tpid, id)
+ if err != nil {
+ return err
+ }
+ if dest != nil {
+ if m.dryRun != true {
+ if err := m.OutStorDB().SetTPSuppliers(dest); err != nil {
+ return err
+ }
+ m.stats[utils.TpSuppliers] += 1
+ }
+ }
+ }
+ }
+ return
+}
+
+func (m *Migrator) migrateTPSuppliers() (err error) {
+ var vrs engine.Versions
+ current := engine.CurrentDataDBVersions()
+ vrs, err = m.dmOut.DataDB().GetVersions(utils.TBLTPSuppliers)
+ 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.TpSuppliers] {
+ case current[utils.TpSuppliers]:
+ if m.sameStorDB {
+ return
+ }
+ if err := m.migrateCurrentTPSuppliers(); err != nil {
+ return err
+ }
+ return
+ }
+ return
+}
diff --git a/utils/consts.go b/utils/consts.go
index 2ec7c2d33..66615c7cc 100755
--- a/utils/consts.go
+++ b/utils/consts.go
@@ -405,6 +405,7 @@ const (
MetaSharedGroups = "*shared_groups"
MetaStats = "*stats"
MetaThresholds = "*thresholds"
+ MetaSuppliers = "*suppliers"
Migrator = "migrator"
UnsupportedMigrationTask = "unsupported migration task"
NoStorDBConnection = "not connected to StorDB"
@@ -451,6 +452,7 @@ const (
CacheResourceProfiles = "resource_profiles"
CacheTimings = "timings"
Thresholds = "Thresholds"
+ Suppliers = "Suppliers"
StatS = "stats"
StatService = "StatS"
RALService = "RALs"
@@ -509,6 +511,7 @@ const (
TpActions = "TpActions"
TpDerivedCharges = "TpDerivedCharges"
TpThresholds = "TpThresholds"
+ TpSuppliers = "TpSuppliers"
TpStats = "TpStats"
TpSharedGroups = "TpSharedGroups"
TpRatingProfiles = "TpRatingProfiles"
@@ -562,6 +565,7 @@ const (
MetaTpActions = "*TpActions"
MetaTpDerivedCharges = "*TpDerivedCharges"
MetaTpThresholds = "*TpThresholds"
+ MetaTpSuppliers = "*TpSuppliers"
MetaTpStats = "*TpStats"
MetaTpSharedGroups = "*TpSharedGroups"
MetaTpRatingProfiles = "*TpRatingProfiles"