From 48a518fc99679c38011db03234ed3000579751df Mon Sep 17 00:00:00 2001 From: DanB Date: Mon, 11 Feb 2019 16:42:53 +0100 Subject: [PATCH] RatingProfiles.csv: removing direction and cdrStatQueueIDs --- apier/v1/apier.go | 7 +- apier/v1/tpratingprofiles.go | 21 +++--- .../mysql/create_tariffplan_tables.sql | 4 +- .../postgres/create_tariffplan_tables.sql | 4 +- engine/loader_csv_test.go | 66 +++++++++---------- engine/model_helpers.go | 25 +++---- engine/model_helpers_test.go | 15 ++--- engine/models.go | 18 +++-- engine/ratingprofile.go | 10 +-- engine/storage_mongo_stordb.go | 14 ++-- engine/storage_sql.go | 7 +- engine/tpreader.go | 16 ++--- general_tests/auth_test.go | 6 +- general_tests/costs1_test.go | 6 +- general_tests/datachrg1_test.go | 2 +- general_tests/ddazmbl1_test.go | 4 +- general_tests/ddazmbl2_test.go | 4 +- general_tests/ddazmbl3_test.go | 4 +- general_tests/smschrg1_test.go | 2 +- migrator/tp_rating_profiles.go | 6 +- utils/apitpdata.go | 34 ++++------ 21 files changed, 130 insertions(+), 145 deletions(-) diff --git a/apier/v1/apier.go b/apier/v1/apier.go index dcb5219d4..034ffdde8 100644 --- a/apier/v1/apier.go +++ b/apier/v1/apier.go @@ -392,7 +392,8 @@ func (self *ApierV1) SetRatingProfile(attrs utils.AttrSetRatingProfile, reply *s return fmt.Errorf("%s:RatingPlanActivation:%v", utils.ErrMandatoryIeMissing.Error(), missing) } } - tpRpf := utils.TPRatingProfile{Tenant: attrs.Tenant, Category: attrs.Category, Direction: attrs.Direction, Subject: attrs.Subject} + tpRpf := utils.TPRatingProfile{Tenant: attrs.Tenant, + Category: attrs.Category, Subject: attrs.Subject} keyId := tpRpf.KeyId() var rpfl *engine.RatingProfile if !attrs.Overwrite { @@ -419,8 +420,8 @@ func (self *ApierV1) SetRatingProfile(attrs utils.AttrSetRatingProfile, reply *s &engine.RatingPlanActivation{ ActivationTime: at, RatingPlanId: ra.RatingPlanId, - FallbackKeys: utils.FallbackSubjKeys(tpRpf.Direction, - tpRpf.Tenant, tpRpf.Category, ra.FallbackSubjects)}) + FallbackKeys: utils.FallbackSubjKeys(tpRpf.Tenant, + tpRpf.Category, ra.FallbackSubjects)}) } if err := self.DataManager.SetRatingProfile(rpfl, utils.NonTransactional); err != nil { return utils.NewErrServerError(err) diff --git a/apier/v1/tpratingprofiles.go b/apier/v1/tpratingprofiles.go index 0e8fd351f..f8087e1d1 100644 --- a/apier/v1/tpratingprofiles.go +++ b/apier/v1/tpratingprofiles.go @@ -67,12 +67,12 @@ func (self *ApierV1) GetTPRatingProfileLoadIds(attrs utils.AttrTPRatingProfileId if missing := utils.MissingStructFields(&attrs, []string{"TPid"}); len(missing) != 0 { //Params missing return utils.NewErrMandatoryIeMissing(missing...) } - if ids, err := self.StorDb.GetTpTableIds(attrs.TPid, utils.TBLTPRateProfiles, utils.TPDistinctIds{"loadid"}, map[string]string{ - "tenant": attrs.Tenant, - "category": attrs.Category, - "direction": attrs.Direction, - "subject": attrs.Subject, - }, new(utils.Paginator)); err != nil { + if ids, err := self.StorDb.GetTpTableIds(attrs.TPid, utils.TBLTPRateProfiles, + utils.TPDistinctIds{"loadid"}, map[string]string{ + "tenant": attrs.Tenant, + "category": attrs.Category, + "subject": attrs.Subject, + }, new(utils.Paginator)); err != nil { if err.Error() != utils.ErrNotFound.Error() { err = utils.NewErrServerError(err) } @@ -118,7 +118,9 @@ func (self *ApierV1) GetTPRatingProfileIds(attrs AttrGetTPRatingProfileIds, repl if missing := utils.MissingStructFields(&attrs, []string{"TPid"}); len(missing) != 0 { //Params missing return utils.NewErrMandatoryIeMissing(missing...) } - if ids, err := self.StorDb.GetTpTableIds(attrs.TPid, utils.TBLTPRateProfiles, utils.TPDistinctIds{"loadid", "direction", "tenant", "category", "subject"}, nil, &attrs.Paginator); err != nil { + if ids, err := self.StorDb.GetTpTableIds(attrs.TPid, utils.TBLTPRateProfiles, + utils.TPDistinctIds{"loadid", "direction", "tenant", "category", "subject"}, + nil, &attrs.Paginator); err != nil { if err.Error() != utils.ErrNotFound.Error() { err = utils.NewErrServerError(err) } @@ -138,7 +140,10 @@ func (self *ApierV1) RemTPRatingProfile(attrs AttrGetTPRatingProfile, reply *str if err := tmpRpf.SetRatingProfileId(attrs.RatingProfileId); err != nil { return err } - if err := self.StorDb.RemTpData(utils.TBLTPRateProfiles, attrs.TPid, map[string]string{"loadid": tmpRpf.Loadid, "direction": tmpRpf.Direction, "tenant": tmpRpf.Tenant, "category": tmpRpf.Category, "subject": tmpRpf.Subject}); err != nil { + if err := self.StorDb.RemTpData(utils.TBLTPRateProfiles, + attrs.TPid, map[string]string{"loadid": tmpRpf.Loadid, + "tenant": tmpRpf.Tenant, "category": tmpRpf.Category, + "subject": tmpRpf.Subject}); err != nil { return utils.NewErrServerError(err) } else { *reply = utils.OK diff --git a/data/storage/mysql/create_tariffplan_tables.sql b/data/storage/mysql/create_tariffplan_tables.sql index 7a8622a22..a5d5c7724 100644 --- a/data/storage/mysql/create_tariffplan_tables.sql +++ b/data/storage/mysql/create_tariffplan_tables.sql @@ -106,19 +106,17 @@ CREATE TABLE `tp_rating_profiles` ( `id` int(11) NOT NULL AUTO_INCREMENT, `tpid` varchar(64) NOT NULL, `loadid` varchar(64) NOT NULL, - `direction` varchar(8) NOT NULL, `tenant` varchar(64) NOT NULL, `category` varchar(32) NOT NULL, `subject` varchar(64) NOT NULL, `activation_time` varchar(26) NOT NULL, `rating_plan_tag` varchar(64) NOT NULL, `fallback_subjects` varchar(64), - `cdr_stat_queue_ids` varchar(64), `created_at` TIMESTAMP, PRIMARY KEY (`id`), KEY `tpid` (`tpid`), KEY `tpid_loadid` (`tpid`, `loadid`), - UNIQUE KEY `tpid_loadid_tenant_category_dir_subj_atime` (`tpid`,`loadid`, `tenant`,`category`,`direction`,`subject`,`activation_time`) + UNIQUE KEY `tpid_loadid_tenant_category_dir_subj_atime` (`tpid`,`loadid`, `tenant`,`category`,`subject`,`activation_time`) ); -- diff --git a/data/storage/postgres/create_tariffplan_tables.sql b/data/storage/postgres/create_tariffplan_tables.sql index 81208c4a6..209c2ecb5 100644 --- a/data/storage/postgres/create_tariffplan_tables.sql +++ b/data/storage/postgres/create_tariffplan_tables.sql @@ -102,19 +102,17 @@ CREATE TABLE tp_rating_profiles ( id SERIAL PRIMARY KEY, tpid VARCHAR(64) NOT NULL, loadid VARCHAR(64) NOT NULL, - direction VARCHAR(8) NOT NULL, tenant VARCHAR(64) NOT NULL, category VARCHAR(32) NOT NULL, subject VARCHAR(64) NOT NULL, activation_time VARCHAR(26) NOT NULL, rating_plan_tag VARCHAR(64) NOT NULL, fallback_subjects VARCHAR(64), - cdr_stat_queue_ids VARCHAR(64), created_at TIMESTAMP WITH TIME ZONE, UNIQUE (tpid, loadid, tenant, category, direction, subject, activation_time) ); CREATE INDEX tpratingprofiles_tpid_idx ON tp_rating_profiles (tpid); -CREATE INDEX tpratingprofiles_idx ON tp_rating_profiles (tpid,loadid,direction,tenant,category,subject); +CREATE INDEX tpratingprofiles_idx ON tp_rating_profiles (tpid,loadid,tenant,category,subject); -- -- Table structure for table `tp_shared_groups` diff --git a/engine/loader_csv_test.go b/engine/loader_csv_test.go index 162ad880d..bd78ac1d9 100644 --- a/engine/loader_csv_test.go +++ b/engine/loader_csv_test.go @@ -124,33 +124,33 @@ ANY_PLAN,DATA_RATE,*any,10 DY_PLAN,RT_DY,*any,10 ` ratingProfiles = ` -*out,CUSTOMER_1,0,rif:from:tm,2012-01-01T00:00:00Z,PREMIUM,danb, -*out,CUSTOMER_1,0,rif:from:tm,2012-02-28T00:00:00Z,STANDARD,danb, -*out,CUSTOMER_2,0,danb:87.139.12.167,2012-01-01T00:00:00Z,STANDARD,danb, -*out,CUSTOMER_1,0,danb,2012-01-01T00:00:00Z,PREMIUM,, -*out,vdf,0,rif,2012-01-01T00:00:00Z,EVENING,, -*out,vdf,call,rif,2012-02-28T00:00:00Z,EVENING,, -*out,vdf,call,dan,2012-01-01T00:00:00Z,EVENING,, -*out,vdf,0,minu,2012-01-01T00:00:00Z,EVENING,, -*out,vdf,0,*any,2012-02-28T00:00:00Z,EVENING,, -*out,vdf,0,one,2012-02-28T00:00:00Z,STANDARD,, -*out,vdf,0,inf,2012-02-28T00:00:00Z,STANDARD,inf, -*out,vdf,0,fall,2012-02-28T00:00:00Z,PREMIUM,rif, -*out,test,0,trp,2013-10-01T00:00:00Z,TDRT,rif;danb, -*out,vdf,0,fallback1,2013-11-18T13:45:00Z,G,fallback2, -*out,vdf,0,fallback1,2013-11-18T13:46:00Z,G,fallback2, -*out,vdf,0,fallback1,2013-11-18T13:47:00Z,G,fallback2, -*out,vdf,0,fallback2,2013-11-18T13:45:00Z,R,rif, -*out,cgrates.org,call,*any,2013-01-06T00:00:00Z,RP_UK,, -*out,cgrates.org,call,discounted_minutes,2013-01-06T00:00:00Z,RP_UK_Mobile_BIG5_PKG,, -*out,cgrates.org,data,rif,2013-01-06T00:00:00Z,RP_DATA,, -*out,cgrates.org,call,max,2013-03-23T00:00:00Z,RP_MX,, -*out,cgrates.org,call,nt,2012-02-28T00:00:00Z,GER_ONLY,, -*in,cgrates.org,LCR_STANDARD,max,2013-03-23T00:00:00Z,RP_MX,, -*out,cgrates.org,call,money,2015-02-28T00:00:00Z,EVENING,, -*out,cgrates.org,call,dy,2015-02-28T00:00:00Z,DY_PLAN,, -*out,cgrates.org,call,block,2015-02-28T00:00:00Z,DY_PLAN,, -*out,cgrates.org,call,round,2016-06-30T00:00:00Z,DEFAULT,, +CUSTOMER_1,0,rif:from:tm,2012-01-01T00:00:00Z,PREMIUM,danb +CUSTOMER_1,0,rif:from:tm,2012-02-28T00:00:00Z,STANDARD,danb +CUSTOMER_2,0,danb:87.139.12.167,2012-01-01T00:00:00Z,STANDARD,danb +CUSTOMER_1,0,danb,2012-01-01T00:00:00Z,PREMIUM, +vdf,0,rif,2012-01-01T00:00:00Z,EVENING, +vdf,call,rif,2012-02-28T00:00:00Z,EVENING, +vdf,call,dan,2012-01-01T00:00:00Z,EVENING, +vdf,0,minu,2012-01-01T00:00:00Z,EVENING, +vdf,0,*any,2012-02-28T00:00:00Z,EVENING, +vdf,0,one,2012-02-28T00:00:00Z,STANDARD, +vdf,0,inf,2012-02-28T00:00:00Z,STANDARD,inf +vdf,0,fall,2012-02-28T00:00:00Z,PREMIUM,rif +test,0,trp,2013-10-01T00:00:00Z,TDRT,rif;danb +vdf,0,fallback1,2013-11-18T13:45:00Z,G,fallback2 +vdf,0,fallback1,2013-11-18T13:46:00Z,G,fallback2 +vdf,0,fallback1,2013-11-18T13:47:00Z,G,fallback2 +vdf,0,fallback2,2013-11-18T13:45:00Z,R,rif +cgrates.org,call,*any,2013-01-06T00:00:00Z,RP_UK, +cgrates.org,call,discounted_minutes,2013-01-06T00:00:00Z,RP_UK_Mobile_BIG5_PKG, +cgrates.org,data,rif,2013-01-06T00:00:00Z,RP_DATA, +cgrates.org,call,max,2013-03-23T00:00:00Z,RP_MX, +cgrates.org,call,nt,2012-02-28T00:00:00Z,GER_ONLY, +cgrates.org,LCR_STANDARD,max,2013-03-23T00:00:00Z,RP_MX, +cgrates.org,call,money,2015-02-28T00:00:00Z,EVENING, +cgrates.org,call,dy,2015-02-28T00:00:00Z,DY_PLAN, +cgrates.org,call,block,2015-02-28T00:00:00Z,DY_PLAN, +cgrates.org,call,round,2016-06-30T00:00:00Z,DEFAULT, ` sharedGroups = ` SG1,*any,*lowest, @@ -899,12 +899,12 @@ func TestLoadRatingProfiles(t *testing.T) { rp := csvr.ratingProfiles["*out:test:0:trp"] expected := &RatingProfile{ Id: "*out:test:0:trp", - RatingPlanActivations: RatingPlanActivations{&RatingPlanActivation{ - ActivationTime: time.Date(2013, 10, 1, 0, 0, 0, 0, time.UTC), - RatingPlanId: "TDRT", - FallbackKeys: []string{"*out:test:0:danb", "*out:test:0:rif"}, - CdrStatQueueIds: []string{""}, - }}, + RatingPlanActivations: RatingPlanActivations{ + &RatingPlanActivation{ + ActivationTime: time.Date(2013, 10, 1, 0, 0, 0, 0, time.UTC), + RatingPlanId: "TDRT", + FallbackKeys: []string{"*out:test:0:danb", "*out:test:0:rif"}, + }}, } if !reflect.DeepEqual(rp, expected) { t.Errorf("Error loading rating profile: %+v", rp.RatingPlanActivations[0]) diff --git a/engine/model_helpers.go b/engine/model_helpers.go index 9065ac0ac..83045db3a 100644 --- a/engine/model_helpers.go +++ b/engine/model_helpers.go @@ -599,18 +599,16 @@ func (tps TpRatingProfiles) AsMapTPRatingProfiles() (map[string]*utils.TPRatingP result := make(map[string]*utils.TPRatingProfile) for _, tp := range tps { rp := &utils.TPRatingProfile{ - TPid: tp.Tpid, - LoadId: tp.Loadid, - Direction: tp.Direction, - Tenant: tp.Tenant, - Category: tp.Category, - Subject: tp.Subject, + TPid: tp.Tpid, + LoadId: tp.Loadid, + Tenant: tp.Tenant, + Category: tp.Category, + Subject: tp.Subject, } ra := &utils.TPRatingActivation{ ActivationTime: tp.ActivationTime, RatingPlanId: tp.RatingPlanTag, FallbackSubjects: tp.FallbackSubjects, - CdrStatQueueIds: tp.CdrStatQueueIds, } if existing, exists := result[rp.KeyIdA()]; !exists { rp.RatingPlanActivations = []*utils.TPRatingActivation{ra} @@ -651,24 +649,21 @@ func APItoModelRatingProfile(rp *utils.TPRatingProfile) (result TpRatingProfiles result = append(result, TpRatingProfile{ Tpid: rp.TPid, Loadid: rp.LoadId, - Direction: rp.Direction, Tenant: rp.Tenant, Category: rp.Category, Subject: rp.Subject, ActivationTime: rpa.ActivationTime, RatingPlanTag: rpa.RatingPlanId, FallbackSubjects: rpa.FallbackSubjects, - CdrStatQueueIds: rpa.CdrStatQueueIds, }) } if len(rp.RatingPlanActivations) == 0 { result = append(result, TpRatingProfile{ - Tpid: rp.TPid, - Loadid: rp.LoadId, - Direction: rp.Direction, - Tenant: rp.Tenant, - Category: rp.Category, - Subject: rp.Subject, + Tpid: rp.TPid, + Loadid: rp.LoadId, + Tenant: rp.Tenant, + Category: rp.Category, + Subject: rp.Subject, }) } } diff --git a/engine/model_helpers_test.go b/engine/model_helpers_test.go index 4f6a1e35e..170370af0 100644 --- a/engine/model_helpers_test.go +++ b/engine/model_helpers_test.go @@ -296,12 +296,11 @@ func TestTPRatingPlanAsExportSlice(t *testing.T) { func TestTPRatingProfileAsExportSlice(t *testing.T) { tpRpf := &utils.TPRatingProfile{ - TPid: "TEST_TPID", - LoadId: "TEST_LOADID", - Direction: utils.OUT, - Tenant: "cgrates.org", - Category: "call", - Subject: "*any", + TPid: "TEST_TPID", + LoadId: "TEST_LOADID", + Tenant: "cgrates.org", + Category: "call", + Subject: "*any", RatingPlanActivations: []*utils.TPRatingActivation{ &utils.TPRatingActivation{ ActivationTime: "2014-01-14T00:00:00Z", @@ -314,8 +313,8 @@ func TestTPRatingProfileAsExportSlice(t *testing.T) { }, } expectedSlc := [][]string{ - []string{utils.OUT, "cgrates.org", "call", "*any", "2014-01-14T00:00:00Z", "TEST_RPLAN1", "subj1;subj2", ""}, - []string{utils.OUT, "cgrates.org", "call", "*any", "2014-01-15T00:00:00Z", "TEST_RPLAN2", "subj1;subj2", ""}, + []string{"cgrates.org", "call", "*any", "2014-01-14T00:00:00Z", "TEST_RPLAN1", "subj1;subj2"}, + []string{"cgrates.org", "call", "*any", "2014-01-15T00:00:00Z", "TEST_RPLAN2", "subj1;subj2"}, } ms := APItoModelRatingProfile(tpRpf) diff --git a/engine/models.go b/engine/models.go index d9d15e0d8..44ff1be83 100644 --- a/engine/models.go +++ b/engine/models.go @@ -88,14 +88,12 @@ type TpRatingProfile struct { Id int64 Tpid string Loadid string - Direction string `index:"0" re:"\*out\s*"` - Tenant string `index:"1" re:"[0-9A-Za-z_\.]+\s*"` - Category string `index:"2" re:"\w+\s*"` - Subject string `index:"3" re:"\*any\s*|(\w+;?)+\s*"` - ActivationTime string `index:"4" re:"\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}Z"` - RatingPlanTag string `index:"5" re:"\w+\s*"` - FallbackSubjects string `index:"6" re:"\w+\s*"` - CdrStatQueueIds string `index:"7" re:"\w+\s*"` + Tenant string `index:"0" re:"[0-9A-Za-z_\.]+\s*"` + Category string `index:"1" re:"\w+\s*"` + Subject string `index:"2" re:"\*any\s*|(\w+;?)+\s*"` + ActivationTime string `index:"3" re:"\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}Z"` + RatingPlanTag string `index:"4" re:"\w+\s*"` + FallbackSubjects string `index:"5" re:"\w+\s*"` CreatedAt time.Time } @@ -105,7 +103,6 @@ func (rpf *TpRatingProfile) SetRatingProfileId(id string) error { return fmt.Errorf("Wrong TP Rating Profile Id: %s", id) } rpf.Loadid = ids[0] - rpf.Direction = ids[1] rpf.Tenant = ids[2] rpf.Category = ids[3] rpf.Subject = ids[4] @@ -113,7 +110,8 @@ func (rpf *TpRatingProfile) SetRatingProfileId(id string) error { } func (rpf *TpRatingProfile) GetRatingProfileId() string { - return utils.ConcatenatedKey(rpf.Loadid, rpf.Direction, rpf.Tenant, rpf.Category, rpf.Subject) + return utils.ConcatenatedKey(rpf.Loadid, utils.META_OUT, + rpf.Tenant, rpf.Category, rpf.Subject) } type TpAction struct { diff --git a/engine/ratingprofile.go b/engine/ratingprofile.go index cb524714e..24e7075b4 100644 --- a/engine/ratingprofile.go +++ b/engine/ratingprofile.go @@ -34,14 +34,14 @@ type RatingProfile struct { } type RatingPlanActivation struct { - ActivationTime time.Time - RatingPlanId string - FallbackKeys []string - CdrStatQueueIds []string + ActivationTime time.Time + RatingPlanId string + FallbackKeys []string } func (rpa *RatingPlanActivation) Equal(orpa *RatingPlanActivation) bool { - return rpa.ActivationTime == orpa.ActivationTime && rpa.RatingPlanId == orpa.RatingPlanId + return rpa.ActivationTime == orpa.ActivationTime && + rpa.RatingPlanId == orpa.RatingPlanId } type RatingPlanActivations []*RatingPlanActivation diff --git a/engine/storage_mongo_stordb.go b/engine/storage_mongo_stordb.go index 2d9a6664b..b3ea41392 100644 --- a/engine/storage_mongo_stordb.go +++ b/engine/storage_mongo_stordb.go @@ -313,9 +313,6 @@ func (ms *MongoStorage) GetTPRatingPlans(tpid, id string, pag *utils.Paginator) func (ms *MongoStorage) GetTPRatingProfiles(tp *utils.TPRatingProfile) ([]*utils.TPRatingProfile, error) { filter := bson.M{"tpid": tp.TPid} - if tp.Direction != "" { - filter["direction"] = tp.Direction - } if tp.Tenant != "" { filter["tenant"] = tp.Tenant } @@ -829,12 +826,11 @@ func (ms *MongoStorage) SetTPRatingProfiles(tps []*utils.TPRatingProfile) error return ms.client.UseSession(ms.ctx, func(sctx mongo.SessionContext) (err error) { for _, tp := range tps { _, err = ms.getCol(utils.TBLTPRateProfiles).UpdateOne(sctx, bson.M{ - "tpid": tp.TPid, - "loadid": tp.LoadId, - "direction": tp.Direction, - "tenant": tp.Tenant, - "category": tp.Category, - "subject": tp.Subject, + "tpid": tp.TPid, + "loadid": tp.LoadId, + "tenant": tp.Tenant, + "category": tp.Category, + "subject": tp.Subject, }, bson.M{"$set": tp}, options.Update().SetUpsert(true)) if err != nil { return err diff --git a/engine/storage_sql.go b/engine/storage_sql.go index 8e6b4ab62..b59590abc 100644 --- a/engine/storage_sql.go +++ b/engine/storage_sql.go @@ -389,7 +389,9 @@ func (self *SQLStorage) SetTPRatingProfiles(rpfs []*utils.TPRatingProfile) error } tx := self.db.Begin() for _, rpf := range rpfs { - if err := tx.Where(&TpRatingProfile{Tpid: rpf.TPid, Loadid: rpf.LoadId, Direction: rpf.Direction, Tenant: rpf.Tenant, Category: rpf.Category, Subject: rpf.Subject}).Delete(TpRatingProfile{}).Error; err != nil { + if err := tx.Where(&TpRatingProfile{Tpid: rpf.TPid, Loadid: rpf.LoadId, + Tenant: rpf.Tenant, Category: rpf.Category, + Subject: rpf.Subject}).Delete(TpRatingProfile{}).Error; err != nil { tx.Rollback() return err } @@ -1226,9 +1228,6 @@ func (self *SQLStorage) GetTPRatingProfiles(filter *utils.TPRatingProfile) ([]*u if len(filter.LoadId) != 0 { q = q.Where("loadid = ?", filter.LoadId) } - if len(filter.Direction) != 0 { - q = q.Where("direction = ?", filter.Direction) - } if len(filter.Tenant) != 0 { q = q.Where("tenant = ?", filter.Tenant) } diff --git a/engine/tpreader.go b/engine/tpreader.go index 49d124bd2..8aac9b627 100644 --- a/engine/tpreader.go +++ b/engine/tpreader.go @@ -398,10 +398,10 @@ func (tpr *TpReader) LoadRatingProfilesFiltered(qriedRpf *utils.TPRatingProfile) } resultRatingProfile.RatingPlanActivations = append(resultRatingProfile.RatingPlanActivations, &RatingPlanActivation{ - ActivationTime: at, - RatingPlanId: tpRa.RatingPlanId, - FallbackKeys: utils.FallbackSubjKeys(tpRpf.Direction, tpRpf.Tenant, tpRpf.Category, tpRa.FallbackSubjects), - CdrStatQueueIds: strings.Split(tpRa.CdrStatQueueIds, utils.INFIELD_SEP), + ActivationTime: at, + RatingPlanId: tpRa.RatingPlanId, + FallbackKeys: utils.FallbackSubjKeys(tpRpf.Tenant, + tpRpf.Category, tpRa.FallbackSubjects), }) } if err := tpr.dm.SetRatingProfile(resultRatingProfile, utils.NonTransactional); err != nil { @@ -438,10 +438,10 @@ func (tpr *TpReader) LoadRatingProfiles() (err error) { } rpf.RatingPlanActivations = append(rpf.RatingPlanActivations, &RatingPlanActivation{ - ActivationTime: at, - RatingPlanId: tpRa.RatingPlanId, - FallbackKeys: utils.FallbackSubjKeys(tpRpf.Direction, tpRpf.Tenant, tpRpf.Category, tpRa.FallbackSubjects), - CdrStatQueueIds: strings.Split(tpRa.CdrStatQueueIds, utils.INFIELD_SEP), + ActivationTime: at, + RatingPlanId: tpRa.RatingPlanId, + FallbackKeys: utils.FallbackSubjKeys(tpRpf.Tenant, + tpRpf.Category, tpRa.FallbackSubjects), }) } tpr.ratingProfiles[tpRpf.KeyId()] = rpf diff --git a/general_tests/auth_test.go b/general_tests/auth_test.go index 7c0900380..bff933689 100644 --- a/general_tests/auth_test.go +++ b/general_tests/auth_test.go @@ -47,9 +47,9 @@ func TestAuthLoadCsv(t *testing.T) { DR_ANY_1CNT,*any,RT_1CENTWITHCF,*up,8,,` ratingPlans := `RP_1,DR_GERMANY,*any,10 RP_ANY,DR_ANY_1CNT,*any,10` - ratingProfiles := `*out,cgrates.org,call,testauthpostpaid1,2013-01-06T00:00:00Z,RP_1,, -*out,cgrates.org,call,testauthpostpaid2,2013-01-06T00:00:00Z,RP_1,*any, -*out,cgrates.org,call,*any,2013-01-06T00:00:00Z,RP_ANY,,` + ratingProfiles := `cgrates.org,call,testauthpostpaid1,2013-01-06T00:00:00Z,RP_1, +cgrates.org,call,testauthpostpaid2,2013-01-06T00:00:00Z,RP_1,*any +cgrates.org,call,*any,2013-01-06T00:00:00Z,RP_ANY,` sharedGroups := `` actions := `TOPUP10_AC,*topup_reset,,,,*monetary,*out,,*any,,,*unlimited,,0,10,false,false,10` actionPlans := `TOPUP10_AT,TOPUP10_AC,*asap,10` diff --git a/general_tests/costs1_test.go b/general_tests/costs1_test.go index 11ed9f6bd..874f9b162 100644 --- a/general_tests/costs1_test.go +++ b/general_tests/costs1_test.go @@ -47,9 +47,9 @@ DR_SMS_1,*any,RT_SMS_5c,*up,4,0,` ratingPlans := `RP_RETAIL,DR_RETAIL,ALWAYS,10 RP_DATA1,DR_DATA_1,ALWAYS,10 RP_SMS1,DR_SMS_1,ALWAYS,10` - ratingProfiles := `*out,cgrates.org,call,*any,2012-01-01T00:00:00Z,RP_RETAIL,, -*out,cgrates.org,data,*any,2012-01-01T00:00:00Z,RP_DATA1,, -*out,cgrates.org,sms,*any,2012-01-01T00:00:00Z,RP_SMS1,,` + ratingProfiles := `cgrates.org,call,*any,2012-01-01T00:00:00Z,RP_RETAIL, +cgrates.org,data,*any,2012-01-01T00:00:00Z,RP_DATA1, +cgrates.org,sms,*any,2012-01-01T00:00:00Z,RP_SMS1,` csvr := engine.NewTpReader(dataDB.DataDB(), engine.NewStringCSVStorage(',', dests, timings, rates, destinationRates, ratingPlans, ratingProfiles, "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", ""), "", "") diff --git a/general_tests/datachrg1_test.go b/general_tests/datachrg1_test.go index 03df337c0..9f2afe77b 100644 --- a/general_tests/datachrg1_test.go +++ b/general_tests/datachrg1_test.go @@ -40,7 +40,7 @@ RT_DATA_1c,0,0.001,10,10,0` DR_DATA_2,*any,RT_DATA_1c,*up,4,0,` ratingPlans := `RP_DATA1,DR_DATA_1,TM1,10 RP_DATA1,DR_DATA_2,TM2,10` - ratingProfiles := `*out,cgrates.org,data,*any,2012-01-01T00:00:00Z,RP_DATA1,,` + ratingProfiles := `cgrates.org,data,*any,2012-01-01T00:00:00Z,RP_DATA1,` csvr := engine.NewTpReader(dataDB.DataDB(), engine.NewStringCSVStorage(',', "", timings, rates, destinationRates, ratingPlans, ratingProfiles, "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", ""), "", "") if err := csvr.LoadTimings(); err != nil { diff --git a/general_tests/ddazmbl1_test.go b/general_tests/ddazmbl1_test.go index 3680c5e03..47943a655 100644 --- a/general_tests/ddazmbl1_test.go +++ b/general_tests/ddazmbl1_test.go @@ -45,8 +45,8 @@ RT_UK_Mobile_BIG5,0.01,0.10,1s,1s,0s` DR_UK_Mobile_BIG5,DST_UK_Mobile_BIG5,RT_UK_Mobile_BIG5,*up,8,0,` ratingPlans := `RP_UK_Mobile_BIG5_PKG,DR_UK_Mobile_BIG5_PKG,ALWAYS,10 RP_UK,DR_UK_Mobile_BIG5,ALWAYS,10` - ratingProfiles := `*out,cgrates.org,call,*any,2013-01-06T00:00:00Z,RP_UK,, -*out,cgrates.org,call,discounted_minutes,2013-01-06T00:00:00Z,RP_UK_Mobile_BIG5_PKG,,` + ratingProfiles := `cgrates.org,call,*any,2013-01-06T00:00:00Z,RP_UK, +cgrates.org,call,discounted_minutes,2013-01-06T00:00:00Z,RP_UK_Mobile_BIG5_PKG,` sharedGroups := `` actions := `TOPUP10_AC,*topup_reset,,,,*monetary,*out,,*any,,,*unlimited,,10,10,false,false,10 TOPUP10_AC1,*topup_reset,,,,*voice,*out,,DST_UK_Mobile_BIG5,discounted_minutes,,*unlimited,,40000000000,10,false,false,10` diff --git a/general_tests/ddazmbl2_test.go b/general_tests/ddazmbl2_test.go index e86033d12..39e229132 100644 --- a/general_tests/ddazmbl2_test.go +++ b/general_tests/ddazmbl2_test.go @@ -45,8 +45,8 @@ RT_UK_Mobile_BIG5,0.01,0.10,1s,1s,0s` DR_UK_Mobile_BIG5,DST_UK_Mobile_BIG5,RT_UK_Mobile_BIG5,*up,8,0,` ratingPlans := `RP_UK_Mobile_BIG5_PKG,DR_UK_Mobile_BIG5_PKG,ALWAYS,10 RP_UK,DR_UK_Mobile_BIG5,ALWAYS,10` - ratingProfiles := `*out,cgrates.org,call,*any,2013-01-06T00:00:00Z,RP_UK,, -*out,cgrates.org,call,discounted_minutes,2013-01-06T00:00:00Z,RP_UK_Mobile_BIG5_PKG,,` + ratingProfiles := `cgrates.org,call,*any,2013-01-06T00:00:00Z,RP_UK, +cgrates.org,call,discounted_minutes,2013-01-06T00:00:00Z,RP_UK_Mobile_BIG5_PKG,` sharedGroups := `` actions := `TOPUP10_AC,*topup_reset,,,,*monetary,*out,,*any,,,*unlimited,,0,10,false,false,10 TOPUP10_AC1,*topup_reset,,,,*voice,*out,,DST_UK_Mobile_BIG5,discounted_minutes,,*unlimited,,40s,10,false,false,10` diff --git a/general_tests/ddazmbl3_test.go b/general_tests/ddazmbl3_test.go index a8b7ce900..6265abe91 100644 --- a/general_tests/ddazmbl3_test.go +++ b/general_tests/ddazmbl3_test.go @@ -45,8 +45,8 @@ RT_UK_Mobile_BIG5,0.01,0.10,1s,1s,0s` DR_UK_Mobile_BIG5,DST_UK_Mobile_BIG5,RT_UK_Mobile_BIG5,*up,8,0,` ratingPlans := `RP_UK_Mobile_BIG5_PKG,DR_UK_Mobile_BIG5_PKG,ALWAYS,10 RP_UK,DR_UK_Mobile_BIG5,ALWAYS,10` - ratingProfiles := `*out,cgrates.org,call,*any,2013-01-06T00:00:00Z,RP_UK,, -*out,cgrates.org,call,discounted_minutes,2013-01-06T00:00:00Z,RP_UK_Mobile_BIG5_PKG,,` + ratingProfiles := `cgrates.org,call,*any,2013-01-06T00:00:00Z,RP_UK, +cgrates.org,call,discounted_minutes,2013-01-06T00:00:00Z,RP_UK_Mobile_BIG5_PKG,` sharedGroups := `` actions := `TOPUP10_AC1,*topup_reset,,,,*voice,*out,,DST_UK_Mobile_BIG5,discounted_minutes,,*unlimited,,40s,10,false,false,10` actionPlans := `TOPUP10_AT,TOPUP10_AC1,ASAP,10` diff --git a/general_tests/smschrg1_test.go b/general_tests/smschrg1_test.go index b22824ad2..1b52ac1f6 100644 --- a/general_tests/smschrg1_test.go +++ b/general_tests/smschrg1_test.go @@ -38,7 +38,7 @@ func TestSMSLoadCsvTpSmsChrg1(t *testing.T) { rates := `RT_SMS_5c,0,0.005,1,1,0` destinationRates := `DR_SMS_1,*any,RT_SMS_5c,*up,4,0,` ratingPlans := `RP_SMS1,DR_SMS_1,ALWAYS,10` - ratingProfiles := `*out,cgrates.org,sms,*any,2012-01-01T00:00:00Z,RP_SMS1,,` + ratingProfiles := `cgrates.org,sms,*any,2012-01-01T00:00:00Z,RP_SMS1,` csvr := engine.NewTpReader(dataDB.DataDB(), engine.NewStringCSVStorage(',', "", timings, rates, destinationRates, ratingPlans, ratingProfiles, "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", ""), "", "") if err := csvr.LoadTimings(); err != nil { diff --git a/migrator/tp_rating_profiles.go b/migrator/tp_rating_profiles.go index b37004c77..3d38e1892 100644 --- a/migrator/tp_rating_profiles.go +++ b/migrator/tp_rating_profiles.go @@ -43,8 +43,10 @@ func (m *Migrator) migrateCurrentTPratingprofiles() (err error) { return err } for _, ratPrf := range ratingProfile { - if err := m.storDBIn.StorDB().RemTpData(utils.TBLTPRateProfiles, ratPrf.TPid, map[string]string{"loadid": ratPrf.LoadId, - "direction": ratPrf.Direction, "tenant": ratPrf.Tenant, "category": ratPrf.Category, "subject": ratPrf.Subject}); err != nil { + if err := m.storDBIn.StorDB().RemTpData(utils.TBLTPRateProfiles, ratPrf.TPid, + map[string]string{"loadid": ratPrf.LoadId, + "tenant": ratPrf.Tenant, "category": ratPrf.Category, + "subject": ratPrf.Subject}); err != nil { return err } } diff --git a/utils/apitpdata.go b/utils/apitpdata.go index 69d7045fe..898d55f0d 100755 --- a/utils/apitpdata.go +++ b/utils/apitpdata.go @@ -215,13 +215,12 @@ func NewTPRatingProfileFromKeyId(tpid, loadId, keyId string) (*TPRatingProfile, if len(s) != 4 { return nil, fmt.Errorf("Cannot parse key %s into RatingProfile", keyId) } - return &TPRatingProfile{TPid: tpid, LoadId: loadId, Tenant: s[1], Category: s[2], Direction: s[0], Subject: s[3]}, nil + return &TPRatingProfile{TPid: tpid, LoadId: loadId, Tenant: s[1], Category: s[2], Subject: s[3]}, nil } type TPRatingProfile struct { TPid string // Tariff plan id LoadId string // Gives ability to load specific RatingProfile based on load identifier, hence being able to keep history also in stordb - Direction string // Traffic direction, OUT is the only one supported for now Tenant string // Tenant's Id Category string // TypeOfRecord Subject string // Rating subject, usually the same as account @@ -230,15 +229,15 @@ type TPRatingProfile struct { // Used as key in nosql db (eg: redis) func (self *TPRatingProfile) KeyId() string { - return fmt.Sprintf("%s:%s:%s:%s", self.Direction, self.Tenant, self.Category, self.Subject) + return fmt.Sprintf("%s:%s:%s:%s", META_OUT, self.Tenant, self.Category, self.Subject) } func (self *TPRatingProfile) KeyIdA() string { - return fmt.Sprintf("%s:%s:%s:%s:%s", self.LoadId, self.Direction, self.Tenant, self.Category, self.Subject) + return fmt.Sprintf("%s:%s:%s:%s:%s", self.LoadId, META_OUT, self.Tenant, self.Category, self.Subject) } func (rpf *TPRatingProfile) GetRatingProfilesId() string { - return fmt.Sprintf("%s%s%s%s%s%s%s%s%s", rpf.LoadId, CONCATENATED_KEY_SEP, rpf.Direction, CONCATENATED_KEY_SEP, rpf.Tenant, CONCATENATED_KEY_SEP, rpf.Category, CONCATENATED_KEY_SEP, rpf.Subject) + return fmt.Sprintf("%s%s%s%s%s%s%s%s%s", rpf.LoadId, CONCATENATED_KEY_SEP, META_OUT, CONCATENATED_KEY_SEP, rpf.Tenant, CONCATENATED_KEY_SEP, rpf.Category, CONCATENATED_KEY_SEP, rpf.Subject) } func (rpf *TPRatingProfile) SetRatingProfilesId(id string) error { @@ -247,7 +246,6 @@ func (rpf *TPRatingProfile) SetRatingProfilesId(id string) error { return fmt.Errorf("Wrong TPRatingProfileId: %s", id) } rpf.LoadId = ids[0] - rpf.Direction = ids[1] rpf.Tenant = ids[2] rpf.Category = ids[3] rpf.Subject = ids[4] @@ -257,36 +255,33 @@ func (rpf *TPRatingProfile) SetRatingProfilesId(id string) error { type AttrSetRatingProfile struct { Tenant string // Tenant's Id Category string // TypeOfRecord - Direction string // Traffic direction, OUT is the only one supported for now Subject string // Rating subject, usually the same as account Overwrite bool // Overwrite if exists RatingPlanActivations []*TPRatingActivation // Activate rating plans at specific time } type AttrGetRatingProfile struct { - Tenant string // Tenant's Id - Category string // TypeOfRecord - Direction string // Traffic direction, OUT is the only one supported for now - Subject string // Rating subject, usually the same as account + Tenant string // Tenant's Id + Category string // TypeOfRecord + Subject string // Rating subject, usually the same as account } func (self *AttrGetRatingProfile) GetID() string { - return ConcatenatedKey(self.Direction, self.Tenant, self.Category, self.Subject) + return ConcatenatedKey(META_OUT, self.Tenant, self.Category, self.Subject) } type TPRatingActivation struct { ActivationTime string // Time when this profile will become active, defined as unix epoch time RatingPlanId string // Id of RatingPlan profile FallbackSubjects string // So we follow the api - CdrStatQueueIds string } // Helper to return the subject fallback keys we need in dataDb -func FallbackSubjKeys(direction, tenant, tor, fallbackSubjects string) []string { +func FallbackSubjKeys(tenant, tor, fallbackSubjects string) []string { var sslice sort.StringSlice if len(fallbackSubjects) != 0 { for _, fbs := range strings.Split(fallbackSubjects, string(FALLBACK_SEP)) { - newKey := fmt.Sprintf("%s:%s:%s:%s", direction, tenant, tor, fbs) + newKey := fmt.Sprintf("%s:%s:%s:%s", META_OUT, tenant, tor, fbs) i := sslice.Search(newKey) if i < len(sslice) && sslice[i] != newKey { // not found so insert it @@ -311,11 +306,10 @@ type AttrSetDestination struct { //ToDo } type AttrTPRatingProfileIds struct { - TPid string // Tariff plan id - Tenant string // Tenant's Id - Category string // TypeOfRecord - Direction string // Traffic direction - Subject string // Rating subject, usually the same as account + TPid string // Tariff plan id + Tenant string // Tenant's Id + Category string // TypeOfRecord + Subject string // Rating subject, usually the same as account } type TPActions struct {