From 022ad003d6e34b37b50fb48c4871dd92f0ceccd3 Mon Sep 17 00:00:00 2001 From: Tripon Alexandru-Ionut Date: Wed, 27 Mar 2019 13:42:45 +0200 Subject: [PATCH] Renamed DispatcherS CSV file to DispatcherProfiles.csv --- apier/v1/apier.go | 2 +- apier/v1/tpdispatchers.go | 12 ++++++------ apier/v2/apier.go | 2 +- cmd/cgr-loader/cgr-loader.go | 2 +- config/config_defaults.go | 2 +- config/config_json_test.go | 2 +- config/config_test.go | 2 +- data/storage/mysql/create_tariffplan_tables.sql | 6 +++--- data/storage/postgres/create_tariffplan_tables.sql | 8 ++++---- .../{Dispatchers.csv => DispatcherProfiles.csv} | 0 engine/libtest.go | 2 +- engine/loader_it_test.go | 4 ++-- engine/model_helpers.go | 12 ++++++------ engine/model_helpers_test.go | 8 ++++---- engine/models.go | 2 +- engine/storage_csv.go | 12 ++++++------ engine/storage_interface.go | 4 ++-- engine/storage_map_stordb.go | 4 ++-- engine/storage_mongo_stordb.go | 4 ++-- engine/storage_sql.go | 12 ++++++------ engine/tpexporter.go | 8 ++++---- engine/tpimporter_csv.go | 8 ++++---- engine/tpreader.go | 2 +- loaders/loader.go | 10 +++++----- loaders/loader_test.go | 4 ++-- migrator/tp_dispatchers.go | 4 ++-- migrator/tp_dispatchers_it_test.go | 6 +++--- utils/consts.go | 4 ++-- 28 files changed, 74 insertions(+), 74 deletions(-) rename data/tariffplans/dispatchers/{Dispatchers.csv => DispatcherProfiles.csv} (100%) diff --git a/apier/v1/apier.go b/apier/v1/apier.go index 4dcd2c1e6..5f9bbfdb8 100644 --- a/apier/v1/apier.go +++ b/apier/v1/apier.go @@ -702,7 +702,7 @@ func (self *ApierV1) LoadTariffPlanFromFolder(attrs utils.AttrLoadTpFromFolder, path.Join(attrs.FolderPath, utils.SuppliersCsv), path.Join(attrs.FolderPath, utils.AttributesCsv), path.Join(attrs.FolderPath, utils.ChargersCsv), - path.Join(attrs.FolderPath, utils.DispatchersCsv), + path.Join(attrs.FolderPath, utils.DispatcherProfilesCsv), path.Join(attrs.FolderPath, utils.DispatcherHostsCsv), ), "", self.Config.GeneralCfg().DefaultTimezone, self.CacheS, self.SchedulerS) diff --git a/apier/v1/tpdispatchers.go b/apier/v1/tpdispatchers.go index 5ee2d28e6..0ddd76229 100644 --- a/apier/v1/tpdispatchers.go +++ b/apier/v1/tpdispatchers.go @@ -23,11 +23,11 @@ import ( ) //SetTPDispatcher creates a new DispatcherProfile within a tariff plan -func (self *ApierV1) SetTPDispatcher(attr *utils.TPDispatcherProfile, reply *string) error { +func (self *ApierV1) SetTPDispatcherProfile(attr *utils.TPDispatcherProfile, reply *string) error { if missing := utils.MissingStructFields(attr, []string{"TPid", "Tenant", "ID"}); len(missing) != 0 { return utils.NewErrMandatoryIeMissing(missing...) } - if err := self.StorDb.SetTPDispatchers([]*utils.TPDispatcherProfile{attr}); err != nil { + if err := self.StorDb.SetTPDispatcherProfiles([]*utils.TPDispatcherProfile{attr}); err != nil { return utils.APIErrorHandler(err) } *reply = utils.OK @@ -35,11 +35,11 @@ func (self *ApierV1) SetTPDispatcher(attr *utils.TPDispatcherProfile, reply *str } //GetTPCharger queries specific DispatcherProfile on Tariff plan -func (self *ApierV1) GetTPDispatcher(attr *utils.TPTntID, reply *utils.TPDispatcherProfile) error { +func (self *ApierV1) GetTPDispatcherProfile(attr *utils.TPTntID, reply *utils.TPDispatcherProfile) error { if missing := utils.MissingStructFields(attr, []string{"TPid", "Tenant", "ID"}); len(missing) != 0 { //Params missing return utils.NewErrMandatoryIeMissing(missing...) } - if rls, err := self.StorDb.GetTPDispatchers(attr.TPid, attr.Tenant, attr.ID); err != nil { + if rls, err := self.StorDb.GetTPDispatcherProfiles(attr.TPid, attr.Tenant, attr.ID); err != nil { if err.Error() != utils.ErrNotFound.Error() { err = utils.NewErrServerError(err) } @@ -56,7 +56,7 @@ type AttrGetTPDispatcherIds struct { } //GetTPDispatcherIDs queries dispatcher identities on specific tariff plan. -func (self *ApierV1) GetTPDispatcherIDs(attrs *AttrGetTPDispatcherIds, reply *[]string) error { +func (self *ApierV1) GetTPDispatcherProfileIDs(attrs *AttrGetTPDispatcherIds, reply *[]string) error { if missing := utils.MissingStructFields(attrs, []string{"TPid"}); len(missing) != 0 { //Params missing return utils.NewErrMandatoryIeMissing(missing...) } @@ -73,7 +73,7 @@ func (self *ApierV1) GetTPDispatcherIDs(attrs *AttrGetTPDispatcherIds, reply *[] } //RemTPCharger removes specific DispatcherProfile on Tariff plan -func (self *ApierV1) RemTPDispatcher(attrs *utils.TPTntID, reply *string) error { +func (self *ApierV1) RemTPDispatcherProfile(attrs *utils.TPTntID, reply *string) error { if missing := utils.MissingStructFields(attrs, []string{"TPid", "Tenant", "ID"}); len(missing) != 0 { //Params missing return utils.NewErrMandatoryIeMissing(missing...) } diff --git a/apier/v2/apier.go b/apier/v2/apier.go index bff512d8a..eab7954b8 100644 --- a/apier/v2/apier.go +++ b/apier/v2/apier.go @@ -119,7 +119,7 @@ func (self *ApierV2) LoadTariffPlanFromFolder(attrs utils.AttrLoadTpFromFolder, path.Join(attrs.FolderPath, utils.SuppliersCsv), path.Join(attrs.FolderPath, utils.AttributesCsv), path.Join(attrs.FolderPath, utils.ChargersCsv), - path.Join(attrs.FolderPath, utils.DispatchersCsv), + path.Join(attrs.FolderPath, utils.DispatcherProfilesCsv), path.Join(attrs.FolderPath, utils.DispatcherHostsCsv), ), "", self.Config.GeneralCfg().DefaultTimezone, self.CacheS, self.SchedulerS) diff --git a/cmd/cgr-loader/cgr-loader.go b/cmd/cgr-loader/cgr-loader.go index 621b3f593..bbe945273 100755 --- a/cmd/cgr-loader/cgr-loader.go +++ b/cmd/cgr-loader/cgr-loader.go @@ -300,7 +300,7 @@ func main() { path.Join(*dataPath, utils.SuppliersCsv), path.Join(*dataPath, utils.AttributesCsv), path.Join(*dataPath, utils.ChargersCsv), - path.Join(*dataPath, utils.DispatchersCsv), + path.Join(*dataPath, utils.DispatcherProfilesCsv), path.Join(*dataPath, utils.DispatcherHostsCsv), ) } diff --git a/config/config_defaults.go b/config/config_defaults.go index 6f58a15e1..73bdf1bd9 100755 --- a/config/config_defaults.go +++ b/config/config_defaults.go @@ -645,7 +645,7 @@ const CGRATES_CFG_JSON = ` }, { "type": "*dispatchers", // data source type - "file_name": "Dispatchers.csv", // file name in the tp_in_dir + "file_name": "DispatcherProfiles.csv", // file name in the tp_in_dir "fields": [ {"tag": "Tenant", "field_id": "Tenant", "type": "*composed", "value": "~0", "mandatory": true}, {"tag": "ID", "field_id": "ID", "type": "*composed", "value": "~1", "mandatory": true}, diff --git a/config/config_json_test.go b/config/config_json_test.go index 4fe15d652..1798df544 100755 --- a/config/config_json_test.go +++ b/config/config_json_test.go @@ -1210,7 +1210,7 @@ func TestDfLoaderJsonCfg(t *testing.T) { }, { Type: utils.StringPointer(utils.MetaDispatchers), - File_name: utils.StringPointer(utils.DispatchersCsv), + File_name: utils.StringPointer(utils.DispatcherProfilesCsv), Fields: &[]*FcTemplateJsonCfg{ {Tag: utils.StringPointer(utils.Tenant), Field_id: utils.StringPointer(utils.Tenant), diff --git a/config/config_test.go b/config/config_test.go index 53c79f99f..150e6385d 100755 --- a/config/config_test.go +++ b/config/config_test.go @@ -1391,7 +1391,7 @@ func TestCgrLoaderCfgITDefaults(t *testing.T) { }, { Type: utils.MetaDispatchers, - Filename: utils.DispatchersCsv, + Filename: utils.DispatcherProfilesCsv, Fields: []*FCTemplate{ {Tag: "Tenant", FieldId: "Tenant", diff --git a/data/storage/mysql/create_tariffplan_tables.sql b/data/storage/mysql/create_tariffplan_tables.sql index 98d73f8d3..1069ae009 100644 --- a/data/storage/mysql/create_tariffplan_tables.sql +++ b/data/storage/mysql/create_tariffplan_tables.sql @@ -423,8 +423,8 @@ CREATE TABLE tp_chargers ( -- Table structure for table `tp_dispatchers` -- -DROP TABLE IF EXISTS tp_dispatchers; -CREATE TABLE tp_dispatchers ( +DROP TABLE IF EXISTS tp_dispatcher_profiles; +CREATE TABLE tp_dispatcher_profiles ( `pk` int(11) NOT NULL AUTO_INCREMENT, `tpid` varchar(64) NOT NULL, `tenant` varchar(64) NOT NULL, @@ -443,7 +443,7 @@ CREATE TABLE tp_dispatchers ( `created_at` TIMESTAMP, PRIMARY KEY (`pk`), KEY `tpid` (`tpid`), - UNIQUE KEY `unique_tp_dispatchers` (`tpid`,`tenant`, + UNIQUE KEY `unique_tp_dispatcher_profiles` (`tpid`,`tenant`, `id`,`filter_ids`,`strategy`,`conn_id`,`conn_filter_ids`) ); diff --git a/data/storage/postgres/create_tariffplan_tables.sql b/data/storage/postgres/create_tariffplan_tables.sql index 11f49deae..61f337f86 100644 --- a/data/storage/postgres/create_tariffplan_tables.sql +++ b/data/storage/postgres/create_tariffplan_tables.sql @@ -412,8 +412,8 @@ CREATE INDEX tp_suppliers_unique ON tp_suppliers ("tpid", "tenant", "id", -- Table structure for table `tp_dispatchers` -- - DROP TABLE IF EXISTS tp_dispatchers; - CREATE TABLE tp_dispatchers ( + DROP TABLE IF EXISTS tp_dispatcher_profiles; + CREATE TABLE tp_dispatcher_profiles ( "pk" SERIAL PRIMARY KEY, "tpid" varchar(64) NOT NULL, "tenant" varchar(64) NOT NULL, @@ -431,8 +431,8 @@ CREATE INDEX tp_suppliers_unique ON tp_suppliers ("tpid", "tenant", "id", "weight" decimal(8,2) NOT NULL, "created_at" TIMESTAMP WITH TIME ZONE ); - CREATE INDEX tp_dispatchers_ids ON tp_dispatchers (tpid); - CREATE INDEX tp_dispatchers_unique ON tp_dispatchers ("tpid", "tenant", "id", + CREATE INDEX tp_dispatcher_profiles_ids ON tp_dispatcher_profiles (tpid); + CREATE INDEX tp_dispatcher_profiles_unique ON tp_dispatcher_profiles ("tpid", "tenant", "id", "filter_ids","strategy","conn_id","conn_filter_ids"); -- diff --git a/data/tariffplans/dispatchers/Dispatchers.csv b/data/tariffplans/dispatchers/DispatcherProfiles.csv similarity index 100% rename from data/tariffplans/dispatchers/Dispatchers.csv rename to data/tariffplans/dispatchers/DispatcherProfiles.csv diff --git a/engine/libtest.go b/engine/libtest.go index 337cd0d1f..edc1d5a18 100644 --- a/engine/libtest.go +++ b/engine/libtest.go @@ -146,7 +146,7 @@ func LoadTariffPlanFromFolder(tpPath, timezone string, dm *DataManager, disable_ path.Join(tpPath, utils.SuppliersCsv), path.Join(tpPath, utils.AttributesCsv), path.Join(tpPath, utils.ChargersCsv), - path.Join(tpPath, utils.DispatchersCsv), + path.Join(tpPath, utils.DispatcherProfilesCsv), path.Join(tpPath, utils.DispatcherHostsCsv), ), "", timezone, cacheS, schedulerS) if err := loader.LoadAll(); err != nil { diff --git a/engine/loader_it_test.go b/engine/loader_it_test.go index ecfb5ec14..32caa47ad 100644 --- a/engine/loader_it_test.go +++ b/engine/loader_it_test.go @@ -114,7 +114,7 @@ func TestLoaderITRemoveLoad(t *testing.T) { path.Join(*dataDir, "tariffplans", *tpCsvScenario, utils.SuppliersCsv), path.Join(*dataDir, "tariffplans", *tpCsvScenario, utils.AttributesCsv), path.Join(*dataDir, "tariffplans", *tpCsvScenario, utils.ChargersCsv), - path.Join(*dataDir, "tariffplans", *tpCsvScenario, utils.DispatchersCsv), + path.Join(*dataDir, "tariffplans", *tpCsvScenario, utils.DispatcherProfilesCsv), path.Join(*dataDir, "tariffplans", *tpCsvScenario, utils.DispatcherHostsCsv), ), "", "", nil, nil) @@ -210,7 +210,7 @@ func TestLoaderITLoadFromCSV(t *testing.T) { path.Join(*dataDir, "tariffplans", *tpCsvScenario, utils.SuppliersCsv), path.Join(*dataDir, "tariffplans", *tpCsvScenario, utils.AttributesCsv), path.Join(*dataDir, "tariffplans", *tpCsvScenario, utils.ChargersCsv), - path.Join(*dataDir, "tariffplans", *tpCsvScenario, utils.DispatchersCsv), + path.Join(*dataDir, "tariffplans", *tpCsvScenario, utils.DispatcherProfilesCsv), path.Join(*dataDir, "tariffplans", *tpCsvScenario, utils.DispatcherHostsCsv), ), "", "", nil, nil) diff --git a/engine/model_helpers.go b/engine/model_helpers.go index d759d4d05..ec76c0b1f 100644 --- a/engine/model_helpers.go +++ b/engine/model_helpers.go @@ -2346,9 +2346,9 @@ func APItoChargerProfile(tpCPP *utils.TPChargerProfile, timezone string) (cpp *C return cpp, nil } -type TPDispatchers []*TPDispatcher +type TPDispatcherProfiles []*TPDispatcherProfile -func (tps TPDispatchers) AsTPDispatchers() (result []*utils.TPDispatcherProfile) { +func (tps TPDispatcherProfiles) AsTPDispatcherProfiles() (result []*utils.TPDispatcherProfile) { mst := make(map[string]*utils.TPDispatcherProfile) filterMap := make(map[string]utils.StringMap) contextMap := make(map[string]utils.StringMap) @@ -2477,7 +2477,7 @@ func paramsToString(sp []interface{}) (strategy string) { return } -func APItoModelTPDispatcher(tpDPP *utils.TPDispatcherProfile) (mdls TPDispatchers) { +func APItoModelTPDispatcherProfile(tpDPP *utils.TPDispatcherProfile) (mdls TPDispatcherProfiles) { if tpDPP == nil { return } @@ -2498,7 +2498,7 @@ func APItoModelTPDispatcher(tpDPP *utils.TPDispatcherProfile) (mdls TPDispatcher strategy := paramsToString(tpDPP.StrategyParams) if len(tpDPP.Conns) == 0 { - return append(mdls, &TPDispatcher{ + return append(mdls, &TPDispatcherProfile{ Tpid: tpDPP.TPid, Tenant: tpDPP.Tenant, ID: tpDPP.ID, @@ -2514,7 +2514,7 @@ func APItoModelTPDispatcher(tpDPP *utils.TPDispatcherProfile) (mdls TPDispatcher confilter := strings.Join(tpDPP.Conns[0].FilterIDs, utils.INFIELD_SEP) conparam := paramsToString(tpDPP.Conns[0].Params) - mdls = append(mdls, &TPDispatcher{ + mdls = append(mdls, &TPDispatcherProfile{ Tpid: tpDPP.TPid, Tenant: tpDPP.Tenant, ID: tpDPP.ID, @@ -2534,7 +2534,7 @@ func APItoModelTPDispatcher(tpDPP *utils.TPDispatcherProfile) (mdls TPDispatcher for i := 1; i < len(tpDPP.Conns); i++ { confilter = strings.Join(tpDPP.Conns[i].FilterIDs, utils.INFIELD_SEP) conparam = paramsToString(tpDPP.Conns[i].Params) - mdls = append(mdls, &TPDispatcher{ + mdls = append(mdls, &TPDispatcherProfile{ Tpid: tpDPP.TPid, Tenant: tpDPP.Tenant, ID: tpDPP.ID, diff --git a/engine/model_helpers_test.go b/engine/model_helpers_test.go index 57848629b..4bdd7bed9 100644 --- a/engine/model_helpers_test.go +++ b/engine/model_helpers_test.go @@ -1709,8 +1709,8 @@ func TestAPItoModelTPDispatcher(t *testing.T) { }, }, } - expected := TPDispatchers{ - &TPDispatcher{ + expected := TPDispatcherProfiles{ + &TPDispatcherProfile{ Tpid: "TP1", Tenant: "cgrates.org", ID: "Dsp", @@ -1724,7 +1724,7 @@ func TestAPItoModelTPDispatcher(t *testing.T) { ConnBlocker: false, ConnParameters: "192.168.54.203", }, - &TPDispatcher{ + &TPDispatcherProfile{ Tpid: "TP1", Tenant: "cgrates.org", ID: "Dsp", @@ -1734,7 +1734,7 @@ func TestAPItoModelTPDispatcher(t *testing.T) { ConnParameters: "192.168.54.204", }, } - rcv := APItoModelTPDispatcher(tpDPP) + rcv := APItoModelTPDispatcherProfile(tpDPP) if !reflect.DeepEqual(expected, rcv) { t.Errorf("Expecting : %+v, \n received: %+v", utils.ToJSON(expected), utils.ToJSON(rcv)) } diff --git a/engine/models.go b/engine/models.go index 68d49199b..b903a8245 100644 --- a/engine/models.go +++ b/engine/models.go @@ -386,7 +386,7 @@ type TPCharger struct { CreatedAt time.Time } -type TPDispatcher struct { +type TPDispatcherProfile struct { PK uint `gorm:"primary_key"` Tpid string // Tenant string `index:"0" re:""` diff --git a/engine/storage_csv.go b/engine/storage_csv.go index d913c58e3..3ff06c179 100644 --- a/engine/storage_csv.go +++ b/engine/storage_csv.go @@ -672,8 +672,8 @@ func (csvs *CSVStorage) GetTPChargers(tpid, tenant, id string) ([]*utils.TPCharg return tpCPPs.AsTPChargers(), nil } -func (csvs *CSVStorage) GetTPDispatchers(tpid, tenant, id string) ([]*utils.TPDispatcherProfile, error) { - csvReader, fp, err := csvs.readerFunc(csvs.dispatcherProfilesFn, csvs.sep, getColumnCount(TPDispatcher{})) +func (csvs *CSVStorage) GetTPDispatcherProfiles(tpid, tenant, id string) ([]*utils.TPDispatcherProfile, error) { + csvReader, fp, err := csvs.readerFunc(csvs.dispatcherProfilesFn, csvs.sep, getColumnCount(TPDispatcherProfile{})) if err != nil { // allow writing of the other values return nil, nil @@ -681,22 +681,22 @@ func (csvs *CSVStorage) GetTPDispatchers(tpid, tenant, id string) ([]*utils.TPDi if fp != nil { defer fp.Close() } - var tpDPPs TPDispatchers + var tpDPPs TPDispatcherProfiles for record, err := csvReader.Read(); err != io.EOF; record, err = csvReader.Read() { if err != nil { log.Printf("bad line in %s, %s\n", csvs.dispatcherProfilesFn, err.Error()) return nil, err } - if dpp, err := csvLoad(TPDispatcher{}, record); err != nil { + if dpp, err := csvLoad(TPDispatcherProfile{}, record); err != nil { log.Print("error loading tpDispatcherProfile: ", err) return nil, err } else { - dpp := dpp.(TPDispatcher) + dpp := dpp.(TPDispatcherProfile) dpp.Tpid = tpid tpDPPs = append(tpDPPs, &dpp) } } - return tpDPPs.AsTPDispatchers(), nil + return tpDPPs.AsTPDispatcherProfiles(), nil } func (csvs *CSVStorage) GetTPDispatcherHosts(tpid, tenant, id string) ([]*utils.TPDispatcherHost, error) { diff --git a/engine/storage_interface.go b/engine/storage_interface.go index d220333db..7c914b037 100644 --- a/engine/storage_interface.go +++ b/engine/storage_interface.go @@ -180,7 +180,7 @@ type LoadReader interface { GetTPSuppliers(string, string, string) ([]*utils.TPSupplierProfile, error) GetTPAttributes(string, string, string) ([]*utils.TPAttributeProfile, error) GetTPChargers(string, string, string) ([]*utils.TPChargerProfile, error) - GetTPDispatchers(string, string, string) ([]*utils.TPDispatcherProfile, error) + GetTPDispatcherProfiles(string, string, string) ([]*utils.TPDispatcherProfile, error) GetTPDispatcherHosts(string, string, string) ([]*utils.TPDispatcherHost, error) } @@ -204,7 +204,7 @@ type LoadWriter interface { SetTPSuppliers([]*utils.TPSupplierProfile) error SetTPAttributes([]*utils.TPAttributeProfile) error SetTPChargers([]*utils.TPChargerProfile) error - SetTPDispatchers([]*utils.TPDispatcherProfile) error + SetTPDispatcherProfiles([]*utils.TPDispatcherProfile) error SetTPDispatcherHosts([]*utils.TPDispatcherHost) error } diff --git a/engine/storage_map_stordb.go b/engine/storage_map_stordb.go index 2a23fbfab..0cd887c35 100755 --- a/engine/storage_map_stordb.go +++ b/engine/storage_map_stordb.go @@ -85,7 +85,7 @@ func (ms *MapStorage) GetTPAttributes(tpid, tenant, id string) (attrs []*utils.T func (ms *MapStorage) GetTPChargers(tpid, tenant, id string) (attrs []*utils.TPChargerProfile, err error) { return nil, utils.ErrNotImplemented } -func (ms *MapStorage) GetTPDispatchers(tpid, tenant, id string) (attrs []*utils.TPDispatcherProfile, err error) { +func (ms *MapStorage) GetTPDispatcherProfiles(tpid, tenant, id string) (attrs []*utils.TPDispatcherProfile, err error) { return nil, utils.ErrNotImplemented } func (ms *MapStorage) GetTPDispatcherHosts(tpid, tenant, id string) (attrs []*utils.TPDispatcherHost, err error) { @@ -150,7 +150,7 @@ func (ms *MapStorage) SetTPAttributes(attributes []*utils.TPAttributeProfile) (e func (ms *MapStorage) SetTPChargers(cpps []*utils.TPChargerProfile) (err error) { return utils.ErrNotImplemented } -func (ms *MapStorage) SetTPDispatchers(dpps []*utils.TPDispatcherProfile) (err error) { +func (ms *MapStorage) SetTPDispatcherProfiles(dpps []*utils.TPDispatcherProfile) (err error) { return utils.ErrNotImplemented } func (ms *MapStorage) SetTPDispatcherHosts(dpps []*utils.TPDispatcherHost) (err error) { diff --git a/engine/storage_mongo_stordb.go b/engine/storage_mongo_stordb.go index cf4ef165c..3be376050 100644 --- a/engine/storage_mongo_stordb.go +++ b/engine/storage_mongo_stordb.go @@ -1427,7 +1427,7 @@ func (ms *MongoStorage) SetTPChargers(tpCPP []*utils.TPChargerProfile) (err erro }) } -func (ms *MongoStorage) GetTPDispatchers(tpid, tenant, id string) ([]*utils.TPDispatcherProfile, error) { +func (ms *MongoStorage) GetTPDispatcherProfiles(tpid, tenant, id string) ([]*utils.TPDispatcherProfile, error) { filter := bson.M{"tpid": tpid} if id != "" { filter["id"] = id @@ -1457,7 +1457,7 @@ func (ms *MongoStorage) GetTPDispatchers(tpid, tenant, id string) ([]*utils.TPDi return results, err } -func (ms *MongoStorage) SetTPDispatchers(tpDPPs []*utils.TPDispatcherProfile) (err error) { +func (ms *MongoStorage) SetTPDispatcherProfiles(tpDPPs []*utils.TPDispatcherProfile) (err error) { if len(tpDPPs) == 0 { return } diff --git a/engine/storage_sql.go b/engine/storage_sql.go index f75f10065..4e8739959 100644 --- a/engine/storage_sql.go +++ b/engine/storage_sql.go @@ -681,18 +681,18 @@ func (self *SQLStorage) SetTPChargers(tpCPPs []*utils.TPChargerProfile) error { return nil } -func (self *SQLStorage) SetTPDispatchers(tpDPPs []*utils.TPDispatcherProfile) error { +func (self *SQLStorage) SetTPDispatcherProfiles(tpDPPs []*utils.TPDispatcherProfile) error { if len(tpDPPs) == 0 { return nil } tx := self.db.Begin() for _, dpp := range tpDPPs { // Remove previous - if err := tx.Where(&TPDispatcher{Tpid: dpp.TPid, ID: dpp.ID}).Delete(TPDispatcher{}).Error; err != nil { + if err := tx.Where(&TPDispatcherProfile{Tpid: dpp.TPid, ID: dpp.ID}).Delete(TPDispatcherProfile{}).Error; err != nil { tx.Rollback() return err } - for _, mst := range APItoModelTPDispatcher(dpp) { + for _, mst := range APItoModelTPDispatcherProfile(dpp) { if err := tx.Save(&mst).Error; err != nil { tx.Rollback() return err @@ -1534,8 +1534,8 @@ func (self *SQLStorage) GetTPChargers(tpid, tenant, id string) ([]*utils.TPCharg return arls, nil } -func (self *SQLStorage) GetTPDispatchers(tpid, tenant, id string) ([]*utils.TPDispatcherProfile, error) { - var dpps TPDispatchers +func (self *SQLStorage) GetTPDispatcherProfiles(tpid, tenant, id string) ([]*utils.TPDispatcherProfile, error) { + var dpps TPDispatcherProfiles q := self.db.Where("tpid = ?", tpid) if len(id) != 0 { q = q.Where("id = ?", id) @@ -1546,7 +1546,7 @@ func (self *SQLStorage) GetTPDispatchers(tpid, tenant, id string) ([]*utils.TPDi if err := q.Find(&dpps).Error; err != nil { return nil, err } - arls := dpps.AsTPDispatchers() + arls := dpps.AsTPDispatcherProfiles() if len(arls) == 0 { return arls, utils.ErrNotFound } diff --git a/engine/tpexporter.go b/engine/tpexporter.go index 28ef0d02b..02206ca5f 100644 --- a/engine/tpexporter.go +++ b/engine/tpexporter.go @@ -284,14 +284,14 @@ func (self *TPExporter) Run() error { } } - storDataDispatchers, err := self.storDb.GetTPDispatchers(self.tpID, "", "") + storDataDispatcherProfiles, err := self.storDb.GetTPDispatcherProfiles(self.tpID, "", "") if err != nil && err.Error() != utils.ErrNotFound.Error() { return err } - for _, sd := range storDataDispatchers { - sdModels := APItoModelTPDispatcher(sd) + for _, sd := range storDataDispatcherProfiles { + sdModels := APItoModelTPDispatcherProfile(sd) for _, sdModel := range sdModels { - toExportMap[utils.DispatchersCsv] = append(toExportMap[utils.DispatchersCsv], sdModel) + toExportMap[utils.DispatcherProfilesCsv] = append(toExportMap[utils.DispatcherProfilesCsv], sdModel) } } diff --git a/engine/tpimporter_csv.go b/engine/tpimporter_csv.go index aa616be22..278e424a0 100644 --- a/engine/tpimporter_csv.go +++ b/engine/tpimporter_csv.go @@ -59,7 +59,7 @@ var fileHandlers = map[string]func(*TPCSVImporter, string) error{ utils.SuppliersCsv: (*TPCSVImporter).importSuppliers, utils.AttributesCsv: (*TPCSVImporter).importAttributeProfiles, utils.ChargersCsv: (*TPCSVImporter).importChargerProfiles, - utils.DispatchersCsv: (*TPCSVImporter).importDispatcherProfiles, + utils.DispatcherProfilesCsv: (*TPCSVImporter).importDispatcherProfiles, utils.DispatcherHostsCsv: (*TPCSVImporter).importDispatcherHosts, } @@ -83,7 +83,7 @@ func (self *TPCSVImporter) Run() error { path.Join(self.DirPath, utils.SuppliersCsv), path.Join(self.DirPath, utils.AttributesCsv), path.Join(self.DirPath, utils.ChargersCsv), - path.Join(self.DirPath, utils.DispatchersCsv), + path.Join(self.DirPath, utils.DispatcherProfilesCsv), path.Join(self.DirPath, utils.DispatcherHostsCsv), ) files, _ := ioutil.ReadDir(self.DirPath) @@ -357,11 +357,11 @@ func (self *TPCSVImporter) importDispatcherProfiles(fn string) error { if self.Verbose { log.Printf("Processing file: <%s> ", fn) } - dpps, err := self.csvr.GetTPDispatchers(self.TPid, "", "") + dpps, err := self.csvr.GetTPDispatcherProfiles(self.TPid, "", "") if err != nil { return err } - return self.StorDb.SetTPDispatchers(dpps) + return self.StorDb.SetTPDispatcherProfiles(dpps) } func (self *TPCSVImporter) importDispatcherHosts(fn string) error { diff --git a/engine/tpreader.go b/engine/tpreader.go index c8711f0c1..b34df6e24 100644 --- a/engine/tpreader.go +++ b/engine/tpreader.go @@ -1270,7 +1270,7 @@ func (tpr *TpReader) LoadChargerProfiles() error { } func (tpr *TpReader) LoadDispatcherProfilesFiltered(tag string) (err error) { - rls, err := tpr.lr.GetTPDispatchers(tpr.tpid, "", tag) + rls, err := tpr.lr.GetTPDispatcherProfiles(tpr.tpid, "", tag) if err != nil { return err } diff --git a/loaders/loader.go b/loaders/loader.go index 07f09ed45..4a2120460 100644 --- a/loaders/loader.go +++ b/loaders/loader.go @@ -480,21 +480,21 @@ func (ldr *Loader) storeLoadedData(loaderType string, } case utils.MetaDispatchers: for _, lDataSet := range lds { - dispModels := make(engine.TPDispatchers, len(lDataSet)) + dispModels := make(engine.TPDispatcherProfiles, len(lDataSet)) for i, ld := range lDataSet { - dispModels[i] = new(engine.TPDispatcher) + dispModels[i] = new(engine.TPDispatcherProfile) if err = utils.UpdateStructWithIfaceMap(dispModels[i], ld); err != nil { return } } - for _, tpDsp := range dispModels.AsTPDispatchers() { + for _, tpDsp := range dispModels.AsTPDispatcherProfiles() { dsp, err := engine.APItoDispatcherProfile(tpDsp, ldr.timezone) if err != nil { return err } if ldr.dryRun { utils.Logger.Info( - fmt.Sprintf("<%s-%s> DRY_RUN: AttributeProfile: %s", + fmt.Sprintf("<%s-%s> DRY_RUN: DispatcherProfile: %s", utils.LoaderS, ldr.ldrID, utils.ToJSON(dsp))) continue } @@ -516,7 +516,7 @@ func (ldr *Loader) storeLoadedData(loaderType string, dsp := engine.APItoDispatcherHost(tpDsp) if ldr.dryRun { utils.Logger.Info( - fmt.Sprintf("<%s-%s> DRY_RUN: AttributeProfile: %s", + fmt.Sprintf("<%s-%s> DRY_RUN: DispatcherHost: %s", utils.LoaderS, ldr.ldrID, utils.ToJSON(dsp))) continue } diff --git a/loaders/loader_test.go b/loaders/loader_test.go index a2890dc68..67d44ad59 100644 --- a/loaders/loader_test.go +++ b/loaders/loader_test.go @@ -1131,8 +1131,8 @@ cgrates.org,EVENT1,,,,,,ALL,,10,,, csvRdr.Comment = '#' ldr.rdrs = map[string]map[string]*openedCSVFile{ utils.MetaDispatchers: map[string]*openedCSVFile{ - utils.DispatchersCsv: &openedCSVFile{ - fileName: utils.DispatchersCsv, + utils.DispatcherProfilesCsv: &openedCSVFile{ + fileName: utils.DispatcherProfilesCsv, rdr: rdr, csvRdr: csvRdr, }, diff --git a/migrator/tp_dispatchers.go b/migrator/tp_dispatchers.go index 85fac4c8a..7a61e2afb 100644 --- a/migrator/tp_dispatchers.go +++ b/migrator/tp_dispatchers.go @@ -38,13 +38,13 @@ func (m *Migrator) migrateCurrentTPDispatchers() (err error) { return err } for _, id := range ids { - dispatchers, err := m.storDBIn.StorDB().GetTPDispatchers(tpid, "", id) + dispatchers, err := m.storDBIn.StorDB().GetTPDispatcherProfiles(tpid, "", id) if err != nil { return err } if dispatchers != nil { if m.dryRun != true { - if err := m.storDBOut.StorDB().SetTPDispatchers(dispatchers); err != nil { + if err := m.storDBOut.StorDB().SetTPDispatcherProfiles(dispatchers); err != nil { return err } for _, dispatcher := range dispatchers { diff --git a/migrator/tp_dispatchers_it_test.go b/migrator/tp_dispatchers_it_test.go index 8d2397935..4f4748771 100644 --- a/migrator/tp_dispatchers_it_test.go +++ b/migrator/tp_dispatchers_it_test.go @@ -123,7 +123,7 @@ func testTpDispITPopulate(t *testing.T) { Weight: 10, }, } - if err := tpDispMigrator.storDBIn.StorDB().SetTPDispatchers(tpDisps); err != nil { + if err := tpDispMigrator.storDBIn.StorDB().SetTPDispatcherProfiles(tpDisps); err != nil { t.Error("Error when setting TpDispatchers ", err.Error()) } currentVersion := engine.CurrentStorDBVersions() @@ -141,7 +141,7 @@ func testTpDispITMove(t *testing.T) { } func testTpDispITCheckData(t *testing.T) { - result, err := tpDispMigrator.storDBOut.StorDB().GetTPDispatchers("TP1", "cgrates.org", "Dsp1") + result, err := tpDispMigrator.storDBOut.StorDB().GetTPDispatcherProfiles("TP1", "cgrates.org", "Dsp1") if err != nil { t.Fatal("Error when getting TpDispatchers ", err.Error()) } @@ -149,7 +149,7 @@ func testTpDispITCheckData(t *testing.T) { t.Errorf("Expecting: %+v, received: %+v", utils.ToJSON(tpDisps[0]), utils.ToJSON(result[0])) } - result, err = tpDispMigrator.storDBIn.StorDB().GetTPDispatchers("TP1", "cgrates.org", "Dsp1") + result, err = tpDispMigrator.storDBIn.StorDB().GetTPDispatcherProfiles("TP1", "cgrates.org", "Dsp1") if err != utils.ErrNotFound { t.Error(err) } diff --git a/utils/consts.go b/utils/consts.go index c39bbb102..08ba4bcc5 100755 --- a/utils/consts.go +++ b/utils/consts.go @@ -911,7 +911,7 @@ const ( SuppliersCsv = "Suppliers.csv" AttributesCsv = "Attributes.csv" ChargersCsv = "Chargers.csv" - DispatchersCsv = "Dispatchers.csv" + DispatcherProfilesCsv = "DispatcherProfiles.csv" DispatcherHostsCsv = "DispatcherHosts.csv" ) @@ -939,7 +939,7 @@ const ( TBLTPChargers = "tp_chargers" TBLVersions = "versions" OldSMCosts = "sm_costs" - TBLTPDispatchers = "tp_dispatchers" + TBLTPDispatchers = "tp_dispatcher_profiles" TBLTPDispatcherHosts = "tp_dispatcher_hosts" )