mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-11 18:16:24 +05:00
Migrator discover tenant from key instead of taking it from config fixes #2006
This commit is contained in:
committed by
Dan Christian Bogos
parent
d7e421911d
commit
c53a3903de
@@ -46,14 +46,16 @@ type v1AttributeProfile struct {
|
||||
|
||||
func (m *Migrator) migrateCurrentAttributeProfile() (err error) {
|
||||
var ids []string
|
||||
tenant := config.CgrConfig().GeneralCfg().DefaultTenant
|
||||
ids, err = m.dmIN.DataManager().DataDB().GetKeysForPrefix(utils.AttributeProfilePrefix)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
for _, id := range ids {
|
||||
idg := strings.TrimPrefix(id, utils.AttributeProfilePrefix+tenant+":")
|
||||
attrPrf, err := m.dmIN.DataManager().GetAttributeProfile(tenant, idg, false, false, utils.NonTransactional)
|
||||
tntID := strings.SplitN(strings.TrimPrefix(id, utils.AttributeProfilePrefix), utils.InInFieldSep, 2)
|
||||
if len(tntID) < 2 {
|
||||
return fmt.Errorf("Invalid key <%s> when migrating attributes", id)
|
||||
}
|
||||
attrPrf, err := m.dmIN.DataManager().GetAttributeProfile(tntID[0], tntID[1], false, false, utils.NonTransactional)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -63,8 +65,8 @@ func (m *Migrator) migrateCurrentAttributeProfile() (err error) {
|
||||
if err := m.dmOut.DataManager().SetAttributeProfile(attrPrf, true); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := m.dmIN.DataManager().RemoveAttributeProfile(tenant,
|
||||
idg, utils.NonTransactional, false); err != nil {
|
||||
if err := m.dmIN.DataManager().RemoveAttributeProfile(tntID[0],
|
||||
tntID[1], utils.NonTransactional, false); err != nil {
|
||||
return err
|
||||
}
|
||||
m.stats[utils.Attributes]++
|
||||
|
||||
@@ -301,6 +301,25 @@ func testAttrITMigrateAndMove(t *testing.T) {
|
||||
},
|
||||
Weight: 20,
|
||||
}
|
||||
attrPrf2 := &engine.AttributeProfile{
|
||||
Tenant: "cgrates.com",
|
||||
ID: "ATTR_1",
|
||||
Contexts: []string{utils.MetaSessionS},
|
||||
FilterIDs: []string{"*string:Accont:1001"},
|
||||
ActivationInterval: &utils.ActivationInterval{
|
||||
ActivationTime: time.Date(2014, 7, 14, 14, 25, 0, 0, time.UTC),
|
||||
ExpiryTime: time.Date(2014, 7, 14, 14, 25, 0, 0, time.UTC),
|
||||
},
|
||||
Attributes: []*engine.Attribute{
|
||||
{
|
||||
FilterIDs: []string{"*string:FL1:In1"},
|
||||
Path: utils.MetaReq + utils.NestingSep + "FL1",
|
||||
Type: utils.MetaVariable,
|
||||
Value: config.NewRSRParsersMustCompile("Al1", true, utils.INFIELD_SEP),
|
||||
},
|
||||
},
|
||||
Weight: 20,
|
||||
}
|
||||
switch attrAction {
|
||||
case utils.Migrate:
|
||||
err := attrMigrator.dmIN.setV1AttributeProfile(v1Attribute)
|
||||
@@ -343,22 +362,29 @@ func testAttrITMigrateAndMove(t *testing.T) {
|
||||
if err := attrMigrator.dmIN.DataManager().SetAttributeProfile(attrPrf, false); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
if err := attrMigrator.dmIN.DataManager().SetAttributeProfile(attrPrf2, false); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
currentVersion := engine.CurrentDataDBVersions()
|
||||
err := attrMigrator.dmOut.DataManager().DataDB().SetVersions(currentVersion, false)
|
||||
if err != nil {
|
||||
t.Error("Error when setting version for Attributes ", err.Error())
|
||||
}
|
||||
|
||||
_, err = attrMigrator.dmOut.DataManager().GetAttributeProfile("cgrates.org",
|
||||
"ATTR_1", false, false, utils.NonTransactional)
|
||||
if err != utils.ErrNotFound {
|
||||
// make sure we don't have attributes in dmOut
|
||||
if _, err = attrMigrator.dmOut.DataManager().GetAttributeProfile("cgrates.org",
|
||||
"ATTR_1", false, false, utils.NonTransactional); err == nil || err != utils.ErrNotFound {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if _, err = attrMigrator.dmOut.DataManager().GetAttributeProfile("cgrates.com",
|
||||
"ATTR_1", false, false, utils.NonTransactional); err == nil || err != utils.ErrNotFound {
|
||||
t.Error(err)
|
||||
}
|
||||
// move
|
||||
err, _ = attrMigrator.Migrate([]string{utils.MetaAttributes})
|
||||
if err != nil {
|
||||
t.Error("Error when migrating Attributes ", err.Error())
|
||||
}
|
||||
// verify ATTR_1 with tenant cgrates.org
|
||||
result, err := attrMigrator.dmOut.DataManager().GetAttributeProfile("cgrates.org",
|
||||
"ATTR_1", false, false, utils.NonTransactional)
|
||||
if err != nil {
|
||||
@@ -369,9 +395,24 @@ func testAttrITMigrateAndMove(t *testing.T) {
|
||||
if !reflect.DeepEqual(result, attrPrf) {
|
||||
t.Errorf("Expecting: %+v, received: %+v", attrPrf, result)
|
||||
}
|
||||
result, err = attrMigrator.dmIN.DataManager().GetAttributeProfile("cgrates.org",
|
||||
// verify ATTR_1 with tenant cgrates.com
|
||||
result, err = attrMigrator.dmOut.DataManager().GetAttributeProfile("cgrates.com",
|
||||
"ATTR_1", false, false, utils.NonTransactional)
|
||||
if err != utils.ErrNotFound {
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
result.Compile()
|
||||
attrPrf2.Compile()
|
||||
if !reflect.DeepEqual(result, attrPrf2) {
|
||||
t.Errorf("Expecting: %+v, received: %+v", attrPrf2, result)
|
||||
}
|
||||
// make sure we don't have attributes in dmIn
|
||||
if _, err = attrMigrator.dmIN.DataManager().GetAttributeProfile("cgrates.org",
|
||||
"ATTR_1", false, false, utils.NonTransactional); err == nil || err != utils.ErrNotFound {
|
||||
t.Error(err)
|
||||
}
|
||||
if _, err = attrMigrator.dmIN.DataManager().GetAttributeProfile("cgrates.com",
|
||||
"ATTR_1", false, false, utils.NonTransactional); err == nil || err != utils.ErrNotFound {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,21 +22,22 @@ import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/cgrates/cgrates/config"
|
||||
"github.com/cgrates/cgrates/engine"
|
||||
"github.com/cgrates/cgrates/utils"
|
||||
)
|
||||
|
||||
func (m *Migrator) migrateCurrentCharger() (err error) {
|
||||
var ids []string
|
||||
tenant := config.CgrConfig().GeneralCfg().DefaultTenant
|
||||
ids, err = m.dmIN.DataManager().DataDB().GetKeysForPrefix(utils.ChargerProfilePrefix)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
for _, id := range ids {
|
||||
idg := strings.TrimPrefix(id, utils.ChargerProfilePrefix+tenant+":")
|
||||
cpp, err := m.dmIN.DataManager().GetChargerProfile(tenant, idg, false, false, utils.NonTransactional)
|
||||
tntID := strings.SplitN(strings.TrimPrefix(id, utils.ChargerProfilePrefix), utils.InInFieldSep, 2)
|
||||
if len(tntID) < 2 {
|
||||
return fmt.Errorf("Invalid key <%s> when migrating chargers", id)
|
||||
}
|
||||
cpp, err := m.dmIN.DataManager().GetChargerProfile(tntID[0], tntID[1], false, false, utils.NonTransactional)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -46,8 +47,8 @@ func (m *Migrator) migrateCurrentCharger() (err error) {
|
||||
if err := m.dmOut.DataManager().SetChargerProfile(cpp, true); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := m.dmIN.DataManager().RemoveChargerProfile(tenant,
|
||||
idg, utils.NonTransactional, false); err != nil {
|
||||
if err := m.dmIN.DataManager().RemoveChargerProfile(tntID[0],
|
||||
tntID[1], utils.NonTransactional, false); err != nil {
|
||||
return err
|
||||
}
|
||||
m.stats[utils.Chargers] += 1
|
||||
|
||||
@@ -185,12 +185,26 @@ func testChrgITMigrateAndMove(t *testing.T) {
|
||||
AttributeIDs: []string{"ATTR_1"},
|
||||
Weight: 20,
|
||||
}
|
||||
chrgPrf2 := &engine.ChargerProfile{
|
||||
Tenant: "cgrates.com",
|
||||
ID: "CHRG_1",
|
||||
FilterIDs: []string{"*string:Accont:1001"},
|
||||
ActivationInterval: &utils.ActivationInterval{
|
||||
ActivationTime: time.Date(2014, 7, 14, 14, 25, 0, 0, time.UTC),
|
||||
ExpiryTime: time.Date(2014, 7, 14, 14, 25, 0, 0, time.UTC),
|
||||
},
|
||||
AttributeIDs: []string{"ATTR_1"},
|
||||
Weight: 20,
|
||||
}
|
||||
switch chrgAction {
|
||||
case utils.Migrate: // for the momment only one version of chargers exists
|
||||
case utils.Move:
|
||||
if err := chrgMigrator.dmIN.DataManager().SetChargerProfile(chrgPrf, false); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
if err := chrgMigrator.dmIN.DataManager().SetChargerProfile(chrgPrf2, false); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
currentVersion := engine.CurrentDataDBVersions()
|
||||
err := chrgMigrator.dmOut.DataManager().DataDB().SetVersions(currentVersion, false)
|
||||
if err != nil {
|
||||
@@ -207,17 +221,24 @@ func testChrgITMigrateAndMove(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Error("Error when migrating Chargers ", err.Error())
|
||||
}
|
||||
result, err := chrgMigrator.dmOut.DataManager().GetChargerProfile("cgrates.org",
|
||||
"CHRG_1", false, false, utils.NonTransactional)
|
||||
if err != nil {
|
||||
if result, err := chrgMigrator.dmOut.DataManager().GetChargerProfile("cgrates.org",
|
||||
"CHRG_1", false, false, utils.NonTransactional); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if !reflect.DeepEqual(result, chrgPrf) {
|
||||
} else if !reflect.DeepEqual(result, chrgPrf) {
|
||||
t.Errorf("Expecting: %+v, received: %+v", chrgPrf, result)
|
||||
}
|
||||
result, err = chrgMigrator.dmIN.DataManager().GetChargerProfile("cgrates.org",
|
||||
"CHRG_1", false, false, utils.NonTransactional)
|
||||
if err != utils.ErrNotFound {
|
||||
if result, err := chrgMigrator.dmOut.DataManager().GetChargerProfile("cgrates.com",
|
||||
"CHRG_1", false, false, utils.NonTransactional); err != nil {
|
||||
t.Fatal(err)
|
||||
} else if !reflect.DeepEqual(result, chrgPrf2) {
|
||||
t.Errorf("Expecting: %+v, received: %+v", chrgPrf2, result)
|
||||
}
|
||||
if _, err = chrgMigrator.dmIN.DataManager().GetChargerProfile("cgrates.org",
|
||||
"CHRG_1", false, false, utils.NonTransactional); err == nil || err != utils.ErrNotFound {
|
||||
t.Error(err)
|
||||
}
|
||||
if _, err = chrgMigrator.dmIN.DataManager().GetChargerProfile("cgrates.com",
|
||||
"CHRG_1", false, false, utils.NonTransactional); err == nil || err != utils.ErrNotFound {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,21 +22,22 @@ import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/cgrates/cgrates/config"
|
||||
"github.com/cgrates/cgrates/engine"
|
||||
"github.com/cgrates/cgrates/utils"
|
||||
)
|
||||
|
||||
func (m *Migrator) migrateCurrentDispatcher() (err error) {
|
||||
var ids []string
|
||||
tenant := config.CgrConfig().GeneralCfg().DefaultTenant
|
||||
ids, err = m.dmIN.DataManager().DataDB().GetKeysForPrefix(utils.DispatcherProfilePrefix)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
for _, id := range ids {
|
||||
idg := strings.TrimPrefix(id, utils.DispatcherProfilePrefix+tenant+":")
|
||||
dpp, err := m.dmIN.DataManager().GetDispatcherProfile(tenant, idg, false, false, utils.NonTransactional)
|
||||
tntID := strings.SplitN(strings.TrimPrefix(id, utils.DispatcherProfilePrefix), utils.InInFieldSep, 2)
|
||||
if len(tntID) < 2 {
|
||||
return fmt.Errorf("Invalid key <%s> when migrating dispatcher profiles", id)
|
||||
}
|
||||
dpp, err := m.dmIN.DataManager().GetDispatcherProfile(tntID[0], tntID[1], false, false, utils.NonTransactional)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -46,8 +47,8 @@ func (m *Migrator) migrateCurrentDispatcher() (err error) {
|
||||
if err := m.dmOut.DataManager().SetDispatcherProfile(dpp, true); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := m.dmIN.DataManager().RemoveDispatcherProfile(tenant,
|
||||
idg, utils.NonTransactional, false); err != nil {
|
||||
if err := m.dmIN.DataManager().RemoveDispatcherProfile(tntID[0],
|
||||
tntID[1], utils.NonTransactional, false); err != nil {
|
||||
return err
|
||||
}
|
||||
m.stats[utils.Dispatchers] += 1
|
||||
@@ -57,14 +58,16 @@ func (m *Migrator) migrateCurrentDispatcher() (err error) {
|
||||
|
||||
func (m *Migrator) migrateCurrentDispatcherHost() (err error) {
|
||||
var ids []string
|
||||
tenant := config.CgrConfig().GeneralCfg().DefaultTenant
|
||||
ids, err = m.dmIN.DataManager().DataDB().GetKeysForPrefix(utils.DispatcherHostPrefix)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
for _, id := range ids {
|
||||
idg := strings.TrimPrefix(id, utils.DispatcherHostPrefix+tenant+":")
|
||||
dpp, err := m.dmIN.DataManager().GetDispatcherHost(tenant, idg, false, false, utils.NonTransactional)
|
||||
tntID := strings.SplitN(strings.TrimPrefix(id, utils.DispatcherHostPrefix), utils.InInFieldSep, 2)
|
||||
if len(tntID) < 2 {
|
||||
return fmt.Errorf("Invalid key <%s> when migrating dispatcher hosts", id)
|
||||
}
|
||||
dpp, err := m.dmIN.DataManager().GetDispatcherHost(tntID[0], tntID[1], false, false, utils.NonTransactional)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -74,8 +77,8 @@ func (m *Migrator) migrateCurrentDispatcherHost() (err error) {
|
||||
if err := m.dmOut.DataManager().SetDispatcherHost(dpp); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := m.dmIN.DataManager().RemoveDispatcherHost(tenant,
|
||||
idg, utils.NonTransactional); err != nil {
|
||||
if err := m.dmIN.DataManager().RemoveDispatcherHost(tntID[0],
|
||||
tntID[1], utils.NonTransactional); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,21 +29,23 @@ import (
|
||||
|
||||
func (m *Migrator) migrateCurrentRequestFilter() (err error) {
|
||||
var ids []string
|
||||
tenant := config.CgrConfig().GeneralCfg().DefaultTenant
|
||||
ids, err = m.dmIN.DataManager().DataDB().GetKeysForPrefix(utils.FilterPrefix)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
for _, id := range ids {
|
||||
idg := strings.TrimPrefix(id, utils.FilterPrefix+tenant+":")
|
||||
fl, err := engine.GetFilter(m.dmIN.DataManager(), tenant, idg, false, false, utils.NonTransactional)
|
||||
tntID := strings.SplitN(strings.TrimPrefix(id, utils.FilterPrefix), utils.InInFieldSep, 2)
|
||||
if len(tntID) < 2 {
|
||||
return fmt.Errorf("Invalid key <%s> when migrating filters", id)
|
||||
}
|
||||
fl, err := engine.GetFilter(m.dmIN.DataManager(), tntID[0], tntID[1], false, false, utils.NonTransactional)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if m.dryRun || fl == nil {
|
||||
continue
|
||||
}
|
||||
if err := m.dmIN.DataManager().RemoveFilter(tenant, idg, utils.NonTransactional); err != nil {
|
||||
if err := m.dmIN.DataManager().RemoveFilter(tntID[0], tntID[1], utils.NonTransactional); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := m.dmOut.DataManager().SetFilter(fl); err != nil {
|
||||
|
||||
@@ -22,21 +22,22 @@ import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/cgrates/cgrates/config"
|
||||
"github.com/cgrates/cgrates/engine"
|
||||
"github.com/cgrates/cgrates/utils"
|
||||
)
|
||||
|
||||
func (m *Migrator) migrateCurrentResource() (err error) {
|
||||
var ids []string
|
||||
tenant := config.CgrConfig().GeneralCfg().DefaultTenant
|
||||
ids, err = m.dmIN.DataManager().DataDB().GetKeysForPrefix(utils.ResourceProfilesPrefix)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
for _, id := range ids {
|
||||
idg := strings.TrimPrefix(id, utils.ResourceProfilesPrefix+tenant+":")
|
||||
res, err := m.dmIN.DataManager().GetResourceProfile(tenant, idg, false, false, utils.NonTransactional)
|
||||
tntID := strings.SplitN(strings.TrimPrefix(id, utils.ResourceProfilesPrefix), utils.InInFieldSep, 2)
|
||||
if len(tntID) < 2 {
|
||||
return fmt.Errorf("Invalid key <%s> when migrating resource profiles", id)
|
||||
}
|
||||
res, err := m.dmIN.DataManager().GetResourceProfile(tntID[0], tntID[1], false, false, utils.NonTransactional)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -46,7 +47,7 @@ func (m *Migrator) migrateCurrentResource() (err error) {
|
||||
if err := m.dmOut.DataManager().SetResourceProfile(res, true); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := m.dmIN.DataManager().RemoveResourceProfile(tenant, idg, utils.NonTransactional, false); err != nil {
|
||||
if err := m.dmIN.DataManager().RemoveResourceProfile(tntID[0], tntID[1], utils.NonTransactional, false); err != nil {
|
||||
return err
|
||||
}
|
||||
m.stats[utils.Resource] += 1
|
||||
|
||||
@@ -61,21 +61,26 @@ type v1Stats []*v1Stat
|
||||
|
||||
func (m *Migrator) moveStatQueueProfile() (err error) {
|
||||
//StatQueueProfile
|
||||
tenant := config.CgrConfig().GeneralCfg().DefaultTenant
|
||||
var ids []string
|
||||
if ids, err = m.dmIN.DataManager().DataDB().GetKeysForPrefix(utils.StatQueueProfilePrefix); err != nil {
|
||||
return err
|
||||
}
|
||||
for _, id := range ids {
|
||||
idg := strings.TrimPrefix(id, utils.StatQueueProfilePrefix+tenant+":")
|
||||
sgs, err := m.dmIN.DataManager().GetStatQueueProfile(tenant, idg, false, false, utils.NonTransactional)
|
||||
tntID := strings.SplitN(strings.TrimPrefix(id, utils.StatQueueProfilePrefix), utils.InInFieldSep, 2)
|
||||
if len(tntID) < 2 {
|
||||
return fmt.Errorf("Invalid key <%s> when migrating stat queue profiles", id)
|
||||
}
|
||||
sgs, err := m.dmIN.DataManager().GetStatQueueProfile(tntID[0], tntID[1], false, false, utils.NonTransactional)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if sgs == nil || m.dryRun {
|
||||
continue
|
||||
}
|
||||
if err = m.dmOut.DataManager().SetStatQueueProfile(sgs, true); err != nil {
|
||||
if err := m.dmOut.DataManager().SetStatQueueProfile(sgs, true); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := m.dmIN.DataManager().RemoveStatQueueProfile(tntID[0], tntID[1], utils.NonTransactional, false); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
@@ -84,14 +89,16 @@ func (m *Migrator) moveStatQueueProfile() (err error) {
|
||||
|
||||
func (m *Migrator) migrateCurrentStats() (err error) {
|
||||
var ids []string
|
||||
tenant := config.CgrConfig().GeneralCfg().DefaultTenant
|
||||
//StatQueue
|
||||
if ids, err = m.dmIN.DataManager().DataDB().GetKeysForPrefix(utils.StatQueuePrefix); err != nil {
|
||||
return err
|
||||
}
|
||||
for _, id := range ids {
|
||||
idg := strings.TrimPrefix(id, utils.StatQueuePrefix+tenant+":")
|
||||
sgs, err := m.dmIN.DataManager().GetStatQueue(tenant, idg, false, false, utils.NonTransactional)
|
||||
tntID := strings.SplitN(strings.TrimPrefix(id, utils.StatQueuePrefix), utils.InInFieldSep, 2)
|
||||
if len(tntID) < 2 {
|
||||
return fmt.Errorf("Invalid key <%s> when migrating stat queues", id)
|
||||
}
|
||||
sgs, err := m.dmIN.DataManager().GetStatQueue(tntID[0], tntID[1], false, false, utils.NonTransactional)
|
||||
if err != nil {
|
||||
|
||||
return err
|
||||
@@ -102,6 +109,9 @@ func (m *Migrator) migrateCurrentStats() (err error) {
|
||||
if err := m.dmOut.DataManager().SetStatQueue(sgs); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := m.dmIN.DataManager().RemoveStatQueue(tntID[0], tntID[1], utils.NonTransactional); err != nil {
|
||||
return err
|
||||
}
|
||||
m.stats[utils.StatS] += 1
|
||||
}
|
||||
|
||||
@@ -177,16 +187,17 @@ func remakeQueue(sq *engine.StatQueue) (out *engine.StatQueue) {
|
||||
|
||||
func (m *Migrator) migrateV2Stats() (err error) {
|
||||
var ids []string
|
||||
tenant := config.CgrConfig().GeneralCfg().DefaultTenant
|
||||
//StatQueue
|
||||
if ids, err = m.dmIN.DataManager().DataDB().GetKeysForPrefix(utils.StatQueuePrefix); err != nil {
|
||||
return err
|
||||
}
|
||||
for _, id := range ids {
|
||||
idg := strings.TrimPrefix(id, utils.StatQueuePrefix+tenant+":")
|
||||
sgs, err := m.dmIN.DataManager().GetStatQueue(tenant, idg, false, false, utils.NonTransactional)
|
||||
tntID := strings.SplitN(strings.TrimPrefix(id, utils.StatQueuePrefix), utils.InInFieldSep, 2)
|
||||
if len(tntID) < 2 {
|
||||
return fmt.Errorf("Invalid key <%s> when migrating stat queues", id)
|
||||
}
|
||||
sgs, err := m.dmIN.DataManager().GetStatQueue(tntID[0], tntID[1], false, false, utils.NonTransactional)
|
||||
if err != nil {
|
||||
|
||||
return err
|
||||
}
|
||||
if sgs == nil || m.dryRun {
|
||||
@@ -195,6 +206,9 @@ func (m *Migrator) migrateV2Stats() (err error) {
|
||||
if err = m.dmOut.DataManager().SetStatQueue(remakeQueue(sgs)); err != nil {
|
||||
return err
|
||||
}
|
||||
if err = m.dmIN.DataManager().RemoveStatQueue(tntID[0], tntID[1], utils.NonTransactional); err != nil {
|
||||
return err
|
||||
}
|
||||
m.stats[utils.StatS] += 1
|
||||
}
|
||||
|
||||
|
||||
@@ -22,21 +22,22 @@ 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().GeneralCfg().DefaultTenant
|
||||
ids, err = m.dmIN.DataManager().DataDB().GetKeysForPrefix(utils.SupplierProfilePrefix)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
for _, id := range ids {
|
||||
idg := strings.TrimPrefix(id, utils.SupplierProfilePrefix+tenant+":")
|
||||
splp, err := m.dmIN.DataManager().GetSupplierProfile(tenant, idg, false, false, utils.NonTransactional)
|
||||
tntID := strings.SplitN(strings.TrimPrefix(id, utils.SupplierProfilePrefix), utils.InInFieldSep, 2)
|
||||
if len(tntID) < 2 {
|
||||
return fmt.Errorf("Invalid key <%s> when migrating supplier profiles", id)
|
||||
}
|
||||
splp, err := m.dmIN.DataManager().GetSupplierProfile(tntID[0], tntID[1], false, false, utils.NonTransactional)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -46,7 +47,7 @@ func (m *Migrator) migrateCurrentSupplierProfile() (err error) {
|
||||
if err := m.dmOut.DataManager().SetSupplierProfile(splp, true); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := m.dmIN.DataManager().RemoveSupplierProfile(tenant, idg, utils.NonTransactional, true); err != nil {
|
||||
if err := m.dmIN.DataManager().RemoveSupplierProfile(tntID[0], tntID[1], utils.NonTransactional, true); err != nil {
|
||||
return err
|
||||
}
|
||||
m.stats[utils.Suppliers] += 1
|
||||
|
||||
@@ -49,15 +49,17 @@ type v2ActionTriggers []*v2ActionTrigger
|
||||
|
||||
func (m *Migrator) migrateCurrentThresholds() (err error) {
|
||||
var ids []string
|
||||
tenant := config.CgrConfig().GeneralCfg().DefaultTenant
|
||||
//Thresholds
|
||||
ids, err = m.dmIN.DataManager().DataDB().GetKeysForPrefix(utils.ThresholdPrefix)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
for _, id := range ids {
|
||||
idg := strings.TrimPrefix(id, utils.ThresholdPrefix+tenant+":")
|
||||
ths, err := m.dmIN.DataManager().GetThreshold(tenant, idg, false, false, utils.NonTransactional)
|
||||
tntID := strings.SplitN(strings.TrimPrefix(id, utils.ThresholdPrefix), utils.InInFieldSep, 2)
|
||||
if len(tntID) < 2 {
|
||||
return fmt.Errorf("Invalid key <%s> when migrating thresholds", id)
|
||||
}
|
||||
ths, err := m.dmIN.DataManager().GetThreshold(tntID[0], tntID[1], false, false, utils.NonTransactional)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -67,6 +69,9 @@ func (m *Migrator) migrateCurrentThresholds() (err error) {
|
||||
if err := m.dmOut.DataManager().SetThreshold(ths); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := m.dmIN.DataManager().RemoveThreshold(tntID[0], tntID[1], utils.NonTransactional); err != nil {
|
||||
return err
|
||||
}
|
||||
m.stats[utils.Thresholds] += 1
|
||||
}
|
||||
//ThresholdProfiles
|
||||
@@ -75,8 +80,11 @@ func (m *Migrator) migrateCurrentThresholds() (err error) {
|
||||
return err
|
||||
}
|
||||
for _, id := range ids {
|
||||
idg := strings.TrimPrefix(id, utils.ThresholdProfilePrefix+tenant+":")
|
||||
ths, err := m.dmIN.DataManager().GetThresholdProfile(tenant, idg, false, false, utils.NonTransactional)
|
||||
tntID := strings.SplitN(strings.TrimPrefix(id, utils.ThresholdProfilePrefix), utils.InInFieldSep, 2)
|
||||
if len(tntID) < 2 {
|
||||
return fmt.Errorf("Invalid key <%s> when migrating threshold profiles", id)
|
||||
}
|
||||
ths, err := m.dmIN.DataManager().GetThresholdProfile(tntID[0], tntID[1], false, false, utils.NonTransactional)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -86,6 +94,9 @@ func (m *Migrator) migrateCurrentThresholds() (err error) {
|
||||
if err := m.dmOut.DataManager().SetThresholdProfile(ths, true); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := m.dmIN.DataManager().RemoveThresholdProfile(tntID[0], tntID[1], utils.NonTransactional, false); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
@@ -31,6 +31,7 @@ cgrates (0.11.0~dev) UNRELEASED; urgency=medium
|
||||
it *internal
|
||||
* [Replicator] Add Limit and StaticTTL otions for Items from
|
||||
DataDB/StorDB
|
||||
* Migrator discover tenant from key instead of taking it from config
|
||||
|
||||
-- Alexandru Tripon <alexandru.tripon@itsyscom.com> Wed, 19 Feb 2020 13:25:52 +0200
|
||||
|
||||
|
||||
Reference in New Issue
Block a user