From d8a44e64ed3eeff597318f118ddec46263a2bdf0 Mon Sep 17 00:00:00 2001 From: edwardro22 Date: Wed, 6 Sep 2017 10:59:09 +0000 Subject: [PATCH] Updated versions --- engine/libtest.go | 2 +- engine/storage_interface.go | 4 +- engine/storage_map.go | 66 +++++---- engine/storage_mongo_datadb.go | 52 ++++---- engine/storage_mongo_stordb.go | 27 ++++ engine/storage_redis.go | 65 ++++++--- engine/version.go | 236 ++++++--------------------------- engine/version_test.go | 49 +++++++ migrator/action.go | 4 +- migrator/action_plan.go | 4 +- migrator/action_trigger.go | 4 +- migrator/sharedgroup.go | 4 +- utils/consts.go | 4 + utils/map.go | 18 ++- utils/map_test.go | 12 ++ 15 files changed, 268 insertions(+), 283 deletions(-) create mode 100644 engine/version_test.go diff --git a/engine/libtest.go b/engine/libtest.go index b80b0c088..1a8e55dfc 100644 --- a/engine/libtest.go +++ b/engine/libtest.go @@ -41,7 +41,7 @@ func InitDataDb(cfg *config.CGRConfig) error { return err } dataDB.LoadRatingCache(nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil) - CheckVersion(dataDB) // Write version before starting + CheckVersions(dataDB) // Write version before starting return nil } diff --git a/engine/storage_interface.go b/engine/storage_interface.go index 9775c680a..27ed86c41 100755 --- a/engine/storage_interface.go +++ b/engine/storage_interface.go @@ -109,8 +109,8 @@ type DataDB interface { RemoveTiming(string, string) error GetLoadHistory(int, bool, string) ([]*utils.LoadInstance, error) AddLoadHistory(*utils.LoadInstance, int, string) error - GetStructVersion() (*StructVersion, error) - SetStructVersion(*StructVersion) error + //GetStructVersion() (*StructVersion, error) + //SetStructVersion(*StructVersion) error GetReqFilterIndexes(dbKey string) (indexes map[string]map[string]utils.StringMap, err error) SetReqFilterIndexes(dbKey string, indexes map[string]map[string]utils.StringMap) (err error) MatchReqFilterIndex(dbKey, fieldName, fieldVal string) (itemIDs utils.StringMap, err error) diff --git a/engine/storage_map.go b/engine/storage_map.go index 9c6413ced..dcae9ea8d 100755 --- a/engine/storage_map.go +++ b/engine/storage_map.go @@ -1285,30 +1285,6 @@ func (ms *MapStorage) GetSMCost(cgrid, source, runid, originHost, originID strin return } -func (ms *MapStorage) SetStructVersion(v *StructVersion) (err error) { - ms.mu.Lock() - defer ms.mu.Unlock() - var result []byte - result, err = ms.ms.Marshal(v) - if err != nil { - return - } - ms.dict[utils.VERSION_PREFIX+"struct"] = result - return -} - -func (ms *MapStorage) GetStructVersion() (rsv *StructVersion, err error) { - ms.mu.RLock() - defer ms.mu.RUnlock() - rsv = &StructVersion{} - if values, ok := ms.dict[utils.VERSION_PREFIX+"struct"]; ok { - err = ms.ms.Unmarshal(values, &rsv) - } else { - return nil, utils.ErrNotFound - } - return -} - func (ms *MapStorage) GetResourceCfg(id string, skipCache bool, transactionID string) (rl *ResourceCfg, err error) { ms.mu.RLock() defer ms.mu.RUnlock() @@ -1508,14 +1484,54 @@ func (ms *MapStorage) MatchReqFilterIndex(dbKey, fldName, fldVal string) (itemID } func (ms *MapStorage) GetVersions(itm string) (vrs Versions, err error) { + ms.mu.Lock() + defer ms.mu.Unlock() + values, ok := ms.dict[itm] + if !ok { + return nil, utils.ErrNotFound + } + err = ms.ms.Unmarshal(values, &vrs) + if err != nil { + return nil, err + } return } func (ms *MapStorage) SetVersions(vrs Versions, overwrite bool) (err error) { + ms.mu.Lock() + defer ms.mu.Unlock() + var result []byte + var x Versions +if !overwrite{ + x,err =ms.GetVersions(utils.TBLVersions) + if err != nil { + return err + } + for key,_:= range vrs{ + if x[key]!=vrs[key]{x[key]=vrs[key]} + } + result, err = ms.ms.Marshal(x) + if err != nil { + return err + } + ms.dict[utils.TBLVersions] = result +return +}else{ + result, err = ms.ms.Marshal(vrs) + if err != nil { + return err + } + if ms.RemoveVersions(vrs);err != nil { + return err + } + ms.dict[utils.TBLVersions] = result return } - +} func (ms *MapStorage) RemoveVersions(vrs Versions) (err error) { + ms.mu.Lock() + defer ms.mu.Unlock() + delete(ms.dict, utils.TBLVersions) return } diff --git a/engine/storage_mongo_datadb.go b/engine/storage_mongo_datadb.go index 412a90e20..151e2f902 100755 --- a/engine/storage_mongo_datadb.go +++ b/engine/storage_mongo_datadb.go @@ -1,4 +1,4 @@ -/* +/* Real-time Online/Offline Charging System (OCS) for Telecom & ISP environments Copyright (C) ITsysCOM GmbH @@ -1819,32 +1819,32 @@ func (ms *MongoStorage) GetAllCdrStats() (css []*CdrStats, err error) { return } -func (ms *MongoStorage) SetStructVersion(v *StructVersion) (err error) { - session, col := ms.conn(colVer) - defer session.Close() - _, err = col.Upsert(bson.M{"key": utils.VERSION_PREFIX + "struct"}, &struct { - Key string - Value *StructVersion - }{utils.VERSION_PREFIX + "struct", v}) - return -} +// func (ms *MongoStorage) SetStructVersion(v *StructVersion) (err error) { +// session, col := ms.conn(colVer) +// defer session.Close() +// _, err = col.Upsert(bson.M{"key": utils.VERSION_PREFIX + "struct"}, &struct { +// Key string +// Value *StructVersion +// }{utils.VERSION_PREFIX + "struct", v}) +// return +// } -func (ms *MongoStorage) GetStructVersion() (rsv *StructVersion, err error) { - var result struct { - Key string - Value StructVersion - } - session, col := ms.conn(colVer) - defer session.Close() - if err = col.Find(bson.M{"key": utils.VERSION_PREFIX + "struct"}).One(&result); err != nil { - if err == mgo.ErrNotFound { - err = utils.ErrNotFound - } - return nil, err - } - rsv = &result.Value - return -} +// func (ms *MongoStorage) GetStructVersion() (rsv *StructVersion, err error) { +// var result struct { +// Key string +// Value StructVersion +// } +// session, col := ms.conn(colVer) +// defer session.Close() +// if err = col.Find(bson.M{"key": utils.VERSION_PREFIX + "struct"}).One(&result); err != nil { +// if err == mgo.ErrNotFound { +// err = utils.ErrNotFound +// } +// return nil, err +// } +// rsv = &result.Value +// return +// } func (ms *MongoStorage) GetResourceCfg(id string, skipCache bool, transactionID string) (rl *ResourceCfg, err error) { key := utils.ResourceConfigsPrefix + id diff --git a/engine/storage_mongo_stordb.go b/engine/storage_mongo_stordb.go index 1980540b1..ecef0d210 100755 --- a/engine/storage_mongo_stordb.go +++ b/engine/storage_mongo_stordb.go @@ -24,6 +24,7 @@ import ( "time" "github.com/cgrates/cgrates/utils" + "gopkg.in/mgo.v2" "gopkg.in/mgo.v2/bson" ) @@ -1198,14 +1199,40 @@ func (ms *MongoStorage) SetTPThreshold(tpTHs []*utils.TPThreshold) (err error) { return } + func (ms *MongoStorage) GetVersions(itm string) (vrs Versions, err error) { +session, col := ms.conn(colVer) + defer session.Close() + if err = col.Find(bson.M{"key":colVer}).One(vrs); err != nil { + if err == mgo.ErrNotFound { + err = utils.ErrNotFound + } + return nil, err + } return } func (ms *MongoStorage) SetVersions(vrs Versions, overwrite bool) (err error) { + session, col := ms.conn(colVer) + defer session.Close() + if overwrite { +if err=ms.RemoveVersions(vrs);err!=nil{ + return err + } + } + _, err = col.Upsert(bson.M{"key":colVer },vrs) return } func (ms *MongoStorage) RemoveVersions(vrs Versions) (err error) { + session, col := ms.conn(colVer) + defer session.Close() + for key,_:=range vrs{ + if err = col.Remove(bson.M{"id": key}); err != nil { + return + } + return nil +} + return } diff --git a/engine/storage_redis.go b/engine/storage_redis.go index bd585440f..1c3ad8ecf 100755 --- a/engine/storage_redis.go +++ b/engine/storage_redis.go @@ -1353,26 +1353,27 @@ func (rs *RedisStorage) GetAllCdrStats() (css []*CdrStats, err error) { return } -func (rs *RedisStorage) SetStructVersion(v *StructVersion) (err error) { - var result []byte - result, err = rs.ms.Marshal(v) - if err != nil { - return - } - return rs.Cmd("SET", utils.VERSION_PREFIX+"struct", result).Err -} +//Remove? +// func (rs *RedisStorage) SetStructVersion(v *StructVersion) (err error) { +// var result []byte +// result, err = rs.ms.Marshal(v) +// if err != nil { +// return +// } +// return rs.Cmd("SET", utils.VERSION_PREFIX+"struct", result).Err +// } -func (rs *RedisStorage) GetStructVersion() (rsv *StructVersion, err error) { - var values []byte - if values, err = rs.Cmd("GET", utils.VERSION_PREFIX+"struct").Bytes(); err != nil { - if err == redis.ErrRespNil { // did not find the destination - err = utils.ErrNotFound - } - return - } - err = rs.ms.Unmarshal(values, &rsv) - return -} +// func (rs *RedisStorage) GetStructVersion() (rsv *StructVersion, err error) { +// var values []byte +// if values, err = rs.Cmd("GET", utils.VERSION_PREFIX+"struct").Bytes(); err != nil { +// if err == redis.ErrRespNil { // did not find the destination +// err = utils.ErrNotFound +// } +// return +// } +// err = rs.ms.Unmarshal(values, &rsv) +// return +// } func (rs *RedisStorage) GetResourceCfg(id string, skipCache bool, transactionID string) (rl *ResourceCfg, err error) { @@ -1546,14 +1547,36 @@ func (rs *RedisStorage) MatchReqFilterIndex(dbKey, fldName, fldVal string) (item } func (rs *RedisStorage) GetVersions(itm string) (vrs Versions, err error) { - return + x, err := rs.Cmd("HGETALL", itm).Map() + if err != nil { + return + } else if len(x) == 0 { + return nil, utils.ErrNotFound + } +vrs,err = utils.MapStringToInt64(x) + if err != nil { + return + } + return } func (rs *RedisStorage) SetVersions(vrs Versions, overwrite bool) (err error) { - return +if overwrite{ + if err=rs.RemoveVersions(vrs);err!=nil{ + return + } +} + return rs.Cmd("HMSET", utils.TBLVersions, vrs).Err } func (rs *RedisStorage) RemoveVersions(vrs Versions) (err error) { +for key,_:=range vrs{ + err = rs.Cmd("HDEL", key).Err + if err!=nil{ + return err + } + } + return } diff --git a/engine/version.go b/engine/version.go index 855f4976b..660a1171c 100644 --- a/engine/version.go +++ b/engine/version.go @@ -24,222 +24,62 @@ import ( "github.com/cgrates/cgrates/utils" ) -func CheckVersion(dataDB DataDB) error { +func CheckVersions(storage Storage) error { +x:=Versions{utils.Accounts: 2,utils.Actions: 2,utils.ActionTriggers: 2,utils.ActionPlans: 2,utils.SharedGroups: 2,utils.COST_DETAILS: 2} // get current db version - if dataDB == nil { - dataDB = dataStorage + if storage == nil { + storage = dataStorage } - dbVersion, err := dataDB.GetStructVersion() + dbVersion, err := storage.GetVersions(utils.TBLVersions) if err != nil { - if lhList, err := dataDB.GetLoadHistory(1, true, utils.NonTransactional); err != nil || len(lhList) == 0 { // no data, write version - if err := dataDB.SetStructVersion(CurrentVersion); err != nil { + if err := storage.SetVersions(x,false); err != nil { utils.Logger.Warning(fmt.Sprintf("Could not write current version to db: %v", err)) } - } else { - // has data but no version => run migration - msg := "Could not detect data structures version: run appropriate migration" - utils.Logger.Crit(msg) - return errors.New(msg) - } + + } else { // comparing versions - if len(CurrentVersion.CompareAndMigrate(dbVersion)) > 0 { + message:=dbVersion.Compare(x) + if len(message) > 0 { + // write the new values - msg := "Migration needed: please backup cgr data and run cgr-loader -migrate" - utils.Logger.Crit(msg) - return errors.New(msg) - } + + msg := "Migration needed: please backup cgr data and run : "+message + + utils.Logger.Crit(msg) + + return errors.New(msg) + } } return nil } -var ( - CurrentVersion = &StructVersion{ - Destinations: "1", - RatingPlans: "1", - RatingProfiles: "1", - Lcrs: "1", - DerivedChargers: "1", - Actions: "1", - ActionPlans: "1", - ActionTriggers: "1", - SharedGroups: "1", - Accounts: "1", - CdrStats: "1", - Users: "1", - Alias: "1", - PubSubs: "1", - LoadHistory: "1", - Cdrs: "1", - SMCosts: "1", - ResourceConfigs: "1", - Timings: "1", - } -) -type StructVersion struct { - Destinations string - RatingPlans string - RatingProfiles string - Lcrs string - DerivedChargers string - Actions string - ActionPlans string - ActionTriggers string - SharedGroups string - Accounts string - CdrStats string - Users string - Alias string - PubSubs string - LoadHistory string - Cdrs string - SMCosts string - ResourceConfigs string - Timings string +func (vers Versions)Compare(curent Versions) string{ +x:=map[string]string{ + utils.Accounts: "cgr-migrator -migrate=*accounts", + utils.Actions: "cgr-migrator -migrate=*actions", + utils.ActionTriggers: "cgr-migrator -migrate=*action_triggers", + utils.ActionPlans: "cgr-migrator -migrate=*action_plans", + utils.SharedGroups: "cgr-migrator -migrate=*shared_groups", + utils.COST_DETAILS: "cgr-migrator -migrate=*cost_details", +} + for x,val :=range x{ + if vers[x]!=curent[x]{ + return val + } + } + return "" } -type MigrationInfo struct { - Prefix string - DbVersion string - CurrentVersion string -} - -func (sv *StructVersion) CompareAndMigrate(dbVer *StructVersion) []*MigrationInfo { - var migrationInfoList []*MigrationInfo - if sv.Destinations != dbVer.Destinations { - migrationInfoList = append(migrationInfoList, &MigrationInfo{ - Prefix: utils.DESTINATION_PREFIX, - DbVersion: dbVer.Destinations, - CurrentVersion: CurrentVersion.Destinations, - }) - - } - if sv.RatingPlans != dbVer.RatingPlans { - migrationInfoList = append(migrationInfoList, &MigrationInfo{ - Prefix: utils.RATING_PLAN_PREFIX, - DbVersion: dbVer.RatingPlans, - CurrentVersion: CurrentVersion.RatingPlans, - }) - } - if sv.RatingProfiles != dbVer.RatingProfiles { - migrationInfoList = append(migrationInfoList, &MigrationInfo{ - Prefix: utils.RATING_PROFILE_PREFIX, - DbVersion: dbVer.RatingProfiles, - CurrentVersion: CurrentVersion.RatingProfiles, - }) - } - if sv.Lcrs != dbVer.Lcrs { - migrationInfoList = append(migrationInfoList, &MigrationInfo{ - Prefix: utils.LCR_PREFIX, - DbVersion: dbVer.Lcrs, - CurrentVersion: CurrentVersion.Lcrs, - }) - } - if sv.DerivedChargers != dbVer.DerivedChargers { - migrationInfoList = append(migrationInfoList, &MigrationInfo{ - Prefix: utils.DERIVEDCHARGERS_PREFIX, - DbVersion: dbVer.DerivedChargers, - CurrentVersion: CurrentVersion.DerivedChargers, - }) - } - if sv.Actions != dbVer.Actions { - migrationInfoList = append(migrationInfoList, &MigrationInfo{ - Prefix: utils.ACTION_PREFIX, - DbVersion: dbVer.Actions, - CurrentVersion: CurrentVersion.Actions, - }) - } - if sv.ActionPlans != dbVer.ActionPlans { - migrationInfoList = append(migrationInfoList, &MigrationInfo{ - Prefix: utils.ACTION_PLAN_PREFIX, - DbVersion: dbVer.ActionPlans, - CurrentVersion: CurrentVersion.ActionPlans, - }) - } - if sv.ActionTriggers != dbVer.ActionTriggers { - migrationInfoList = append(migrationInfoList, &MigrationInfo{ - Prefix: utils.ACTION_TRIGGER_PREFIX, - DbVersion: dbVer.ActionTriggers, - CurrentVersion: CurrentVersion.ActionTriggers, - }) - } - if sv.SharedGroups != dbVer.SharedGroups { - migrationInfoList = append(migrationInfoList, &MigrationInfo{ - Prefix: utils.SHARED_GROUP_PREFIX, - DbVersion: dbVer.SharedGroups, - CurrentVersion: CurrentVersion.SharedGroups, - }) - } - if sv.Accounts != dbVer.Accounts { - migrationInfoList = append(migrationInfoList, &MigrationInfo{ - Prefix: utils.ACCOUNT_PREFIX, - DbVersion: dbVer.Accounts, - CurrentVersion: CurrentVersion.Accounts, - }) - } - if sv.CdrStats != dbVer.CdrStats { - migrationInfoList = append(migrationInfoList, &MigrationInfo{ - Prefix: utils.CDR_STATS_PREFIX, - DbVersion: dbVer.CdrStats, - CurrentVersion: CurrentVersion.CdrStats, - }) - } - if sv.Users != dbVer.Users { - migrationInfoList = append(migrationInfoList, &MigrationInfo{ - Prefix: utils.USERS_PREFIX, - DbVersion: dbVer.Users, - CurrentVersion: CurrentVersion.Users, - }) - } - if sv.Alias != dbVer.Alias { - migrationInfoList = append(migrationInfoList, &MigrationInfo{ - Prefix: utils.ALIASES_PREFIX, - DbVersion: dbVer.Alias, - CurrentVersion: CurrentVersion.Alias, - }) - } - if sv.PubSubs != dbVer.PubSubs { - migrationInfoList = append(migrationInfoList, &MigrationInfo{ - Prefix: utils.PUBSUB_SUBSCRIBERS_PREFIX, - DbVersion: dbVer.PubSubs, - CurrentVersion: CurrentVersion.PubSubs, - }) - } - if sv.LoadHistory != dbVer.LoadHistory { - migrationInfoList = append(migrationInfoList, &MigrationInfo{ - Prefix: utils.LOADINST_KEY, - DbVersion: dbVer.LoadHistory, - CurrentVersion: CurrentVersion.LoadHistory, - }) - } - if sv.Cdrs != dbVer.Cdrs { - migrationInfoList = append(migrationInfoList, &MigrationInfo{ - Prefix: utils.CDRS_SOURCE, - DbVersion: dbVer.RatingPlans, - CurrentVersion: CurrentVersion.RatingPlans, - }) - } - if sv.SMCosts != dbVer.SMCosts { - migrationInfoList = append(migrationInfoList, &MigrationInfo{ - Prefix: utils.SMG, - DbVersion: dbVer.SMCosts, - CurrentVersion: CurrentVersion.SMCosts, - }) - } - if sv.ResourceConfigs != dbVer.ResourceConfigs { - migrationInfoList = append(migrationInfoList, &MigrationInfo{ - Prefix: utils.ResourceConfigsPrefix, - DbVersion: dbVer.ResourceConfigs, - CurrentVersion: CurrentVersion.ResourceConfigs, - }) - } - return migrationInfoList -} func CurrentStorDBVersions() Versions { - return Versions{utils.COST_DETAILS: 2, utils.Accounts: 2} + return Versions{utils.COST_DETAILS: 2} +} + +func CurrentDataDBVersions() Versions { + return Versions{utils.Accounts: 2,utils.Actions: 2,utils.ActionTriggers: 2,utils.ActionPlans: 2,utils.SharedGroups: 2} } // Versions will keep trac of various item versions diff --git a/engine/version_test.go b/engine/version_test.go new file mode 100644 index 000000000..997d63d04 --- /dev/null +++ b/engine/version_test.go @@ -0,0 +1,49 @@ +/* +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 engine + +import ( + "testing" + + "github.com/cgrates/cgrates/utils" +) + +func TestVersionCompare(t *testing.T) { +x:=Versions{utils.Accounts: 2,utils.Actions: 2,utils.ActionTriggers: 2,utils.ActionPlans: 2,utils.SharedGroups: 2,utils.COST_DETAILS: 2} +y:=Versions{utils.Accounts: 1,utils.Actions: 2,utils.ActionTriggers: 2,utils.ActionPlans: 2,utils.SharedGroups: 2,utils.COST_DETAILS: 2} +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} + +message1:=y.Compare(x) +if message1!="cgr-migrator -migrate=*accounts"{ + t.Errorf("Error failed to compare to curent version expected: %s received: %s","cgr-migrator -migrate=*accounts", message1) +} +message2:=z.Compare(x) +if message2!="cgr-migrator -migrate=*action_plans"{ + t.Errorf("Error failed to compare to curent version expected: %s received: %s","cgr-migrator -migrate=*action_plans", message2) +} +message3:=q.Compare(x) +if message3!="cgr-migrator -migrate=*shared_groups"{ + t.Errorf("Error failed to compare to curent version expected: %s received: %s","cgr-migrator -migrate=*shared_groups", message3) +} +message4:=c.Compare(x) +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) +} +} \ No newline at end of file diff --git a/migrator/action.go b/migrator/action.go index 62861787f..44e93bd60 100644 --- a/migrator/action.go +++ b/migrator/action.go @@ -63,12 +63,12 @@ func (m *Migrator) migrateActions() (err error) { } } // All done, update version wtih current one - vrs := engine.Versions{utils.Accounts: engine.CurrentStorDBVersions()[utils.ACTION_PREFIX]} + vrs := engine.Versions{utils.Actions: engine.CurrentStorDBVersions()[utils.Actions]} if err = m.dataDB.SetVersions(vrs, false); err != nil { return utils.NewCGRError(utils.Migrator, utils.ServerErrorCaps, err.Error(), - fmt.Sprintf("error: <%s> when updating Accounts version into StorDB", err.Error())) + fmt.Sprintf("error: <%s> when updating Actions version into dataDB", err.Error())) } return } diff --git a/migrator/action_plan.go b/migrator/action_plan.go index b1096eb8a..2ee1385c4 100644 --- a/migrator/action_plan.go +++ b/migrator/action_plan.go @@ -70,12 +70,12 @@ func (m *Migrator) migrateActionPlans() (err error) { } } // All done, update version wtih current one - vrs := engine.Versions{utils.Accounts: engine.CurrentStorDBVersions()[utils.ACTION_PLAN_PREFIX]} + vrs := engine.Versions{utils.ActionPlans: engine.CurrentDataDBVersions()[utils.ActionPlans]} if err = m.dataDB.SetVersions(vrs, false); err != nil { return utils.NewCGRError(utils.Migrator, utils.ServerErrorCaps, err.Error(), - fmt.Sprintf("error: <%s> when updating Accounts version into StorDB", err.Error())) + fmt.Sprintf("error: <%s> when updating ActionPlans version into dataDB", err.Error())) } return } diff --git a/migrator/action_trigger.go b/migrator/action_trigger.go index 214394791..8d8df88b1 100644 --- a/migrator/action_trigger.go +++ b/migrator/action_trigger.go @@ -59,12 +59,12 @@ func (m *Migrator) migrateActionTriggers() (err error) { } } // All done, update version wtih current one - vrs := engine.Versions{utils.Accounts: engine.CurrentStorDBVersions()[utils.ACTION_TRIGGER_PREFIX]} + vrs := engine.Versions{utils.ActionTriggers: engine.CurrentDataDBVersions()[utils.ActionTriggers]} if err = m.dataDB.SetVersions(vrs, false); err != nil { return utils.NewCGRError(utils.Migrator, utils.ServerErrorCaps, err.Error(), - fmt.Sprintf("error: <%s> when updating Accounts version into StorDB", err.Error())) + fmt.Sprintf("error: <%s> when updating ActionTriggers version into DataDB", err.Error())) } return diff --git a/migrator/sharedgroup.go b/migrator/sharedgroup.go index 1586c5425..c803a2a1d 100644 --- a/migrator/sharedgroup.go +++ b/migrator/sharedgroup.go @@ -48,12 +48,12 @@ func (m *Migrator) migrateSharedGroups() (err error) { } } // All done, update version wtih current one - vrs := engine.Versions{utils.Accounts: engine.CurrentStorDBVersions()[utils.Accounts]} + vrs := engine.Versions{utils.SharedGroups: engine.CurrentStorDBVersions()[utils.SharedGroups]} if err = m.dataDB.SetVersions(vrs, false); err != nil { return utils.NewCGRError(utils.Migrator, utils.ServerErrorCaps, err.Error(), - fmt.Sprintf("error: <%s> when updating Accounts version into StorDB", err.Error())) + fmt.Sprintf("error: <%s> when updating SharedGroups version into dataDB", err.Error())) } return } diff --git a/utils/consts.go b/utils/consts.go index 3c3d63be2..de33b16f8 100755 --- a/utils/consts.go +++ b/utils/consts.go @@ -407,6 +407,10 @@ const ( MetaFileCSV = "*file_csv" MetaFileFWV = "*file_fwv" Accounts = "Accounts" + Actions = "Actions" + ActionPlans = "ActionPlans" + ActionTriggers = "ActionTriggers" + SharedGroups = "SharedGroups" MetaEveryMinute = "*every_minute" MetaHourly = "*hourly" ID = "ID" diff --git a/utils/map.go b/utils/map.go index 3e7916119..1c3d11c46 100644 --- a/utils/map.go +++ b/utils/map.go @@ -17,7 +17,10 @@ along with this program. If not, see */ package utils -import "strings" +import ( + "strings" + "strconv" +) // Converts map[string]string into map[string]interface{} func ConvertMapValStrIf(inMap map[string]string) map[string]interface{} { @@ -190,7 +193,6 @@ func MapKeysReplace(m map[string]struct{}, old, new string) map[string]struct{} return m } */ - // Used to merge multiple maps (eg: output of struct having ExtraFields) func MergeMapsStringIface(mps ...map[string]interface{}) (outMp map[string]interface{}) { outMp = make(map[string]interface{}) @@ -217,3 +219,15 @@ func (fmp FieldMultiplyFactor) Clone() (cln FieldMultiplyFactor) { } return } + +func MapStringToInt64(in map[string]string) (out map[string]int64, err error){ +mapout := make(map[string]int64, len(in)) + for key, val := range in { + x,err:=strconv.Atoi(val) + if err!=nil{ + return nil,err + } + mapout[key] = int64(x) + } + return mapout,nil +} diff --git a/utils/map_test.go b/utils/map_test.go index 770f25a5f..d58f3639f 100644 --- a/utils/map_test.go +++ b/utils/map_test.go @@ -91,3 +91,15 @@ func TestIsEmpty(t *testing.T) { t.Error("Expecting:", expected, ", received:", result) } } + +func TestMapStringToInt64(t *testing.T){ + t1:=map[string]int64{"test":int64(21)} + t2:=map[string]string{"test":"21"} + t3,err:=MapStringToInt64(t2) + if err!=nil{ + t.Error("Got Error: ",err) + } + if !reflect.DeepEqual(t1,t3){ + t.Errorf("Expecting: %+v, received: %+v", t1, t3) + } +} \ No newline at end of file