mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-11 18:16:24 +05:00
Proper ratingprofile order
This commit is contained in:
@@ -99,9 +99,9 @@ CREATE TABLE `tp_rating_profiles` (
|
||||
`tbid` 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(16) NOT NULL,
|
||||
`direction` varchar(8) NOT NULL,
|
||||
`subject` varchar(64) NOT NULL,
|
||||
`activation_time` varchar(24) NOT NULL,
|
||||
`rating_plan_id` varchar(64) NOT NULL,
|
||||
@@ -212,11 +212,11 @@ CREATE TABLE `tp_account_actions` (
|
||||
);
|
||||
|
||||
--
|
||||
-- Table structure for table `tp_lcrs`
|
||||
-- Table structure for table `tp_lcr_rules`
|
||||
--
|
||||
|
||||
DROP TABLE IF EXISTS tp_lcr_rules;
|
||||
CREATE TABLE tp_lcr (
|
||||
CREATE TABLE tp_lcr_rules (
|
||||
`tbid` int(11) NOT NULL AUTO_INCREMENT,
|
||||
`tpid` varchar(64) NOT NULL,
|
||||
`direction` varchar(8) NOT NULL,
|
||||
|
||||
@@ -1,2 +1,2 @@
|
||||
#Tenant,TOR,Direction,Subject,ActivationTime,RatingPlanTag,FallbackSubject
|
||||
cgrates.org,call,*out,*any,2012-01-01T00:00:00Z,RP_RETAIL,
|
||||
#Direction,Tenant,Category,Subject,ActivationTime,RatingPlanId,RatesFallbackSubject
|
||||
*out,cgrates.org,call,*any,2012-01-01T00:00:00Z,RP_RETAIL,
|
||||
|
||||
|
@@ -558,10 +558,10 @@ func (dbr *DbReader) LoadActionTriggers() (err error) {
|
||||
Direction: apiAtr.Direction,
|
||||
ThresholdType: apiAtr.ThresholdType,
|
||||
ThresholdValue: apiAtr.ThresholdValue,
|
||||
Recurrent: apiAtr.Recurrent,
|
||||
DestinationId: apiAtr.DestinationId,
|
||||
Weight: apiAtr.Weight,
|
||||
ActionsId: apiAtr.ActionsId,
|
||||
Recurrent: apiAtr.Recurrent,
|
||||
}
|
||||
}
|
||||
dbr.actionsTriggers[key] = atrs
|
||||
|
||||
@@ -198,8 +198,8 @@ var FileValidators = map[string]*FileLineRegexValidator{
|
||||
regexp.MustCompile(`(?:\w+\s*,\s*){3}(?:\d+.?\d*){1}$`),
|
||||
"Tag([0-9A-Za-z_]),DestinationRatesTag([0-9A-Za-z_]),TimingProfile([0-9A-Za-z_]),Weight([0-9.])"},
|
||||
utils.RATING_PROFILES_CSV: &FileLineRegexValidator{utils.RATE_PROFILES_NRCOLS,
|
||||
regexp.MustCompile(`(?:\w+\s*,\s*){2}(?:\*out\s*,\s*){1}(?:\*any\s*,\s*|(\w+;?)+\s*,\s*){1}(?:\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}Z){1}(?:\w*\s*,?\s*){2}$`),
|
||||
"Tenant([0-9A-Za-z_]),TOR([0-9A-Za-z_]),Direction(*out),Subject([0-9A-Za-z_]|*all),RatesFallbackSubject([0-9A-Za-z_]|<empty>),RatesTimingTag([0-9A-Za-z_]),ActivationTime([0-9T:X])"},
|
||||
regexp.MustCompile(`^(?:\*out\s*),(?:[0-9A-Za-z_\.]+\s*),(?:\w+\s*),(?:\*any\s*|(\w+;?)+\s*),(?:\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}Z),(?:\w+\s*),(?:\w+\s*)?$`),
|
||||
"Direction(*out),Tenant([0-9A-Za-z_]),Category([0-9A-Za-z_]),Subject([0-9A-Za-z_]|*any),ActivationTime([0-9T:X]),RatingPlanId([0-9A-Za-z_]),RatesFallbackSubject([0-9A-Za-z_]|<empty>)"},
|
||||
utils.SHARED_GROUPS_CSV: &FileLineRegexValidator{utils.SHARED_GROUPS_NRCOLS,
|
||||
regexp.MustCompile(`(?:\w+\s*),(?:\*?\w+\s*),(?:\*\w+\s*),(?:\*?\w]+\s*)?`),
|
||||
"Id([0-9A-Za-z_]),Account(*?[0-9A-Za-z_]),Strategy(*[0-9A-Za-z_]),RatingSubject(*?[0-9A-Za-z_])"},
|
||||
|
||||
@@ -53,9 +53,9 @@ DUMMY,INVALID;DATA
|
||||
`
|
||||
|
||||
var ratingProfilesSample = `#Tenant,TOR,Direction,Subject,ActivationTime,RatingPlanTag,FallbackSubject
|
||||
cgrates.org,call,*out,*any,2012-01-01T00:00:00Z,RP_RETAIL,
|
||||
*out,cgrates.org,call,*any,2012-01-01T00:00:00Z,RP_RETAIL,
|
||||
DUMMY,INVALID;DATA
|
||||
cgrates.org,call,*out,subj1;alias1,2012-01-01T00:00:00Z,RP_RETAIL,
|
||||
*out,cgrates.org,call,subj1;alias1,2012-01-01T00:00:00Z,RP_RETAIL,
|
||||
`
|
||||
|
||||
var actionsSample = `#ActionsTag,Action,BalanceType,Direction,Units,ExpiryTime,DestinationTag,RatingSubject,BalanceWeight,SharedGroup,ExtraParameters,Weight
|
||||
|
||||
@@ -20,7 +20,6 @@ package engine
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"fmt"
|
||||
"path"
|
||||
"testing"
|
||||
|
||||
@@ -224,7 +223,6 @@ func TestLoadFromStorDb(t *testing.T) {
|
||||
t.Error("Failed loading action triggers: ", err.Error())
|
||||
}
|
||||
if err := loader.LoadAccountActions(); err != nil {
|
||||
fmt.Printf("Have actionTriggers loaded :%v\n", loader.actionsTriggers)
|
||||
t.Error("Failed loading account actions: ", err.Error())
|
||||
}
|
||||
if err := loader.WriteToDatabase(true, false); err != nil {
|
||||
@@ -298,7 +296,7 @@ func TestMatchLoadCsvWithStor(t *testing.T) {
|
||||
for idx, rs := range []*RedisStorage{rsCsv, rsStor, rsApier} {
|
||||
qVal, err := rs.db.Get(key)
|
||||
if err != nil {
|
||||
t.Fatalf("Could not retrieve key %s, error: %s", key, err.Error())
|
||||
t.Fatalf("Run: %d, could not retrieve key %s, error: %s", idx, key, err.Error())
|
||||
}
|
||||
if idx == 0 { // Only compare at second iteration, first one is to set reference value
|
||||
refVal = qVal
|
||||
|
||||
@@ -261,7 +261,7 @@ func (self *SQLStorage) SetTPRatingProfiles(tpid string, rps map[string]*utils.T
|
||||
return nil //Nothing to set
|
||||
}
|
||||
var buffer bytes.Buffer
|
||||
buffer.WriteString(fmt.Sprintf("INSERT INTO %s (tpid,loadid,tenant,category,direction,subject,activation_time,rating_plan_id,fallback_subjects) VALUES ",
|
||||
buffer.WriteString(fmt.Sprintf("INSERT INTO %s (tpid,loadid,direction,tenant,category,subject,activation_time,rating_plan_id,fallback_subjects) VALUES ",
|
||||
utils.TBL_TP_RATE_PROFILES))
|
||||
i := 0
|
||||
for _, rp := range rps {
|
||||
@@ -269,7 +269,7 @@ func (self *SQLStorage) SetTPRatingProfiles(tpid string, rps map[string]*utils.T
|
||||
if i != 0 { //Consecutive values after the first will be prefixed with "," as separator
|
||||
buffer.WriteRune(',')
|
||||
}
|
||||
buffer.WriteString(fmt.Sprintf("('%s', '%s', '%s', '%s', '%s', '%s', '%s','%s','%s')", tpid, rp.LoadId, rp.Tenant, rp.Category, rp.Direction,
|
||||
buffer.WriteString(fmt.Sprintf("('%s', '%s', '%s', '%s', '%s', '%s', '%s','%s','%s')", tpid, rp.LoadId, rp.Direction, rp.Tenant, rp.Category,
|
||||
rp.Subject, rpa.ActivationTime, rpa.RatingPlanId, rpa.FallbackSubjects))
|
||||
i++
|
||||
}
|
||||
@@ -1031,15 +1031,16 @@ func (self *SQLStorage) GetTpRatingProfiles(qryRpf *utils.TPRatingProfile) (map[
|
||||
if len(qryRpf.LoadId) != 0 {
|
||||
q += fmt.Sprintf(" AND loadid='%s'", qryRpf.LoadId)
|
||||
}
|
||||
if len(qryRpf.Direction) != 0 {
|
||||
q += fmt.Sprintf(" AND direction='%s'", qryRpf.Direction)
|
||||
}
|
||||
if len(qryRpf.Tenant) != 0 {
|
||||
q += fmt.Sprintf(" AND tenant='%s'", qryRpf.Tenant)
|
||||
}
|
||||
if len(qryRpf.Category) != 0 {
|
||||
q += fmt.Sprintf(" AND category='%s'", qryRpf.Category)
|
||||
}
|
||||
if len(qryRpf.Direction) != 0 {
|
||||
q += fmt.Sprintf(" AND direction='%s'", qryRpf.Direction)
|
||||
}
|
||||
|
||||
if len(qryRpf.Subject) != 0 {
|
||||
q += fmt.Sprintf(" AND subject='%s'", qryRpf.Subject)
|
||||
}
|
||||
@@ -1051,10 +1052,10 @@ func (self *SQLStorage) GetTpRatingProfiles(qryRpf *utils.TPRatingProfile) (map[
|
||||
rpfs := make(map[string]*utils.TPRatingProfile)
|
||||
for rows.Next() {
|
||||
var rcvLoadId, tenant, category, direction, subject, fallback_subjects, rating_plan_tag, activation_time string
|
||||
if err := rows.Scan(&rcvLoadId, &tenant, &category, &direction, &subject, &activation_time, &rating_plan_tag, &fallback_subjects); err != nil {
|
||||
if err := rows.Scan(&rcvLoadId, &direction, &tenant, &category, &subject, &activation_time, &rating_plan_tag, &fallback_subjects); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
rp := &utils.TPRatingProfile{TPid: qryRpf.TPid, LoadId: rcvLoadId, Tenant: tenant, Category: category, Direction: direction, Subject: subject}
|
||||
rp := &utils.TPRatingProfile{TPid: qryRpf.TPid, LoadId: rcvLoadId, Direction: direction, Tenant: tenant, Category: category, Subject: subject}
|
||||
if existingRp, has := rpfs[rp.KeyId()]; !has {
|
||||
rp.RatingPlanActivations = []*utils.TPRatingActivation{
|
||||
&utils.TPRatingActivation{ActivationTime: activation_time, RatingPlanId: rating_plan_tag, FallbackSubjects: fallback_subjects}}
|
||||
|
||||
@@ -486,10 +486,10 @@ func TestSetGetTPActionTriggers(t *testing.T) {
|
||||
ActionsId: "LOG_BALANCE",
|
||||
}
|
||||
mpAtrgs := map[string][]*utils.TPActionTrigger{TEST_SQL: []*utils.TPActionTrigger{atrg}}
|
||||
if err := mysql.SetTPActionTriggers(TEST_SQL, mpAtrgs); err != nil {
|
||||
if err := mysql.SetTPActionTriggers(TEST_SQL+"1", mpAtrgs); err != nil {
|
||||
t.Error("Unexpected error: ", err.Error())
|
||||
}
|
||||
if rcvMpAtrgs, err := mysql.GetTpActionTriggers(TEST_SQL, TEST_SQL); err != nil {
|
||||
if rcvMpAtrgs, err := mysql.GetTpActionTriggers(TEST_SQL+"1", TEST_SQL); err != nil {
|
||||
t.Error("Unexpected error: ", err.Error())
|
||||
} else if !reflect.DeepEqual(mpAtrgs, rcvMpAtrgs) {
|
||||
t.Errorf("Expecting: %v, received: %v", mpAtrgs, rcvMpAtrgs)
|
||||
|
||||
@@ -258,7 +258,7 @@ func (self *TPCSVImporter) importRatingProfiles(fn string) error {
|
||||
}
|
||||
continue
|
||||
}
|
||||
tenant, tor, direction, subject, ratingPlanTag, fallbacksubject := record[0], record[1], record[2], record[3], record[5], record[6]
|
||||
direction, tenant, tor, subject, ratingPlanTag, fallbacksubject := record[0], record[1], record[2], record[3], record[5], record[6]
|
||||
_, err = utils.ParseDate(record[4])
|
||||
if err != nil {
|
||||
if self.Verbose {
|
||||
|
||||
@@ -27,7 +27,7 @@ const (
|
||||
TBL_TP_RATING_PLANS = "tp_rating_plans"
|
||||
TBL_TP_RATE_PROFILES = "tp_rating_profiles"
|
||||
TBL_TP_SHARED_GROUPS = "tp_shared_groups"
|
||||
TBL_TP_LCRS = "tp_lcrs"
|
||||
TBL_TP_LCRS = "tp_lcr_rules"
|
||||
TBL_TP_ACTIONS = "tp_actions"
|
||||
TBL_TP_ACTION_PLANS = "tp_action_plans"
|
||||
TBL_TP_ACTION_TRIGGERS = "tp_action_triggers"
|
||||
|
||||
Reference in New Issue
Block a user