Add SessionsCosts in migrator and versions

This commit is contained in:
TeoV
2018-02-01 13:20:55 +02:00
committed by Dan Christian Bogos
parent 3be693fcac
commit 465f0635eb
6 changed files with 98 additions and 2 deletions

View File

@@ -90,7 +90,8 @@ func (vers Versions) Compare(curent Versions, storType string) string {
utils.SharedGroups: "cgr-migrator -migrate=*shared_groups",
}
stor := map[string]string{
utils.COST_DETAILS: "cgr-migrator -migrate=*cost_details",
utils.COST_DETAILS: "cgr-migrator -migrate=*cost_details",
utils.SessionsCosts: "cgr-migrator -migrate=*sessions_costs",
}
switch storType {
case utils.MONGO:
@@ -141,6 +142,7 @@ func CurrentDataDBVersions() Versions {
func CurrentStorDBVersions() Versions {
return Versions{
utils.COST_DETAILS: 2,
utils.SessionsCosts: 2,
utils.TpRatingPlans: 1,
utils.TpFilters: 1,
utils.TpDestinationRates: 1,

View File

@@ -29,7 +29,8 @@ func TestVersionCompare(t *testing.T) {
z := Versions{utils.Accounts: 2, utils.Actions: 2, utils.ActionTriggers: 2, utils.ActionPlans: 1, utils.SharedGroups: 2, utils.COST_DETAILS: 2}
q := Versions{utils.Accounts: 2, utils.Actions: 2, utils.ActionTriggers: 2, utils.ActionPlans: 2, utils.SharedGroups: 1, utils.COST_DETAILS: 2}
c := Versions{utils.Accounts: 2, utils.Actions: 2, utils.ActionTriggers: 2, utils.ActionPlans: 2, utils.SharedGroups: 2, utils.COST_DETAILS: 1}
a := Versions{utils.Accounts: 2, utils.Actions: 2, utils.ActionTriggers: 2, utils.ActionPlans: 2, utils.SharedGroups: 2, utils.COST_DETAILS: 2, utils.SessionsCosts: 1}
b := Versions{utils.Accounts: 2, utils.Actions: 2, utils.ActionTriggers: 2, utils.ActionPlans: 2, utils.SharedGroups: 2, utils.COST_DETAILS: 2, utils.SessionsCosts: 2}
message1 := y.Compare(x, utils.MONGO)
if message1 != "cgr-migrator -migrate=*accounts" {
t.Errorf("Error failed to compare to curent version expected: %s received: %s", "cgr-migrator -migrate=*accounts", message1)
@@ -46,4 +47,13 @@ func TestVersionCompare(t *testing.T) {
if message4 != "cgr-migrator -migrate=*cost_details" {
t.Errorf("Error failed to compare to curent version expected: %s received: %s", "cgr-migrator -migrate=*cost_details", message4)
}
message5 := a.Compare(b, utils.MYSQL)
if message5 != "cgr-migrator -migrate=*sessions_costs" {
t.Errorf("Error failed to compare to curent version expected: %s received: %s", "cgr-migrator -migrate=*sessions_costs", message5)
}
message6 := a.Compare(b, utils.POSTGRES)
if message6 != "cgr-migrator -migrate=*sessions_costs" {
t.Errorf("Error failed to compare to curent version expected: %s received: %s", "cgr-migrator -migrate=*sessions_costs", message6)
}
}

View File

@@ -115,6 +115,8 @@ func (m *Migrator) Migrate(taskIDs []string) (err error, stats map[string]int) {
} else {
log.Print("Cannot dryRun SetVersions!")
}
case utils.MetaSessionsCosts:
err = m.migrateSessionsCosts()
case utils.MetaCostDetails:
err = m.migrateCostDetails()
case utils.MetaAccounts:

View File

@@ -50,6 +50,7 @@ var sTestsITMigrator = []func(t *testing.T){
testMigratorActions,
testMigratorSharedGroups,
testMigratorStats,
testMigratorSessionsCosts,
testFlush,
testMigratorAlias,
//FIXME testMigratorReverseAlias,
@@ -1112,6 +1113,37 @@ func testMigratorStats(t *testing.T) {
}
}
func testMigratorSessionsCosts(t *testing.T) {
switch action {
case Move:
currentVersion := engine.CurrentStorDBVersions()
currentVersion[utils.SessionsCosts] = 1
err := mig.dmOut.DataDB().SetVersions(currentVersion, false)
if err != nil {
t.Error("Error when setting version for SessionsCosts ", err.Error())
}
err, _ = mig.Migrate([]string{utils.MetaSessionsCosts})
if err == nil {
t.Error("Expecting error , received: nil ")
}
if vrs, err := mig.dmOut.DataDB().GetVersions(utils.SessionsCosts); err != nil {
t.Error(err)
} else if vrs[utils.SessionsCosts] != 1 {
t.Errorf("Expecting: 1, received: %+v", vrs[utils.SessionsCosts])
}
currentVersion = engine.CurrentStorDBVersions()
err = mig.dmOut.DataDB().SetVersions(currentVersion, false)
if err != nil {
t.Error("Error when setting version for SessionsCosts ", err.Error())
}
if vrs, err := mig.dmOut.DataDB().GetVersions(utils.SessionsCosts); err != nil {
t.Error(err)
} else if vrs[utils.SessionsCosts] != 2 {
t.Errorf("Expecting: 2, received: %+v", vrs[utils.SessionsCosts])
}
}
}
func testMigratorThreshold(t *testing.T) {
tim := time.Date(2012, time.February, 27, 23, 59, 59, 0, time.UTC)
tenant := config.CgrConfig().DefaultTenant

View File

@@ -0,0 +1,48 @@
/*
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 (
"errors"
"fmt"
"github.com/cgrates/cgrates/engine"
"github.com/cgrates/cgrates/utils"
)
func (m *Migrator) migrateSessionsCosts() (err error) {
var vrs engine.Versions
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")
}
if vrs[utils.SessionsCosts] == 1 {
msg := "Migration needed: please backup cgrates data and run from data/storage the scripts for MySql and Postgres"
return errors.New(msg)
}
return nil
}

View File

@@ -368,6 +368,7 @@ const (
SchedulerNotRunningCaps = "SCHEDULLER_NOT_RUNNING"
MetaScheduler = "*scheduler"
MetaCostDetails = "*cost_details"
MetaSessionsCosts = "*sessions_costs"
MetaAccounts = "*accounts"
MetaActionPlans = "*action_plans"
MetaActionTriggers = "*action_triggers"
@@ -439,6 +440,7 @@ const (
Disabled = "Disabled"
Action = "Action"
MetaNow = "*now"
SessionsCosts = "SessionsCosts"
TpRatingPlans = "TpRatingPlans"
TpFilters = "TpFilters"
TpDestinationRates = "TpDestinationRates"