diff --git a/data/tariffplans/testtp/ResourceLimits.csv b/data/tariffplans/testtp/ResourceLimits.csv index 1e5d8d01e..2531cf85a 100755 --- a/data/tariffplans/testtp/ResourceLimits.csv +++ b/data/tariffplans/testtp/ResourceLimits.csv @@ -1,4 +1,4 @@ -#Id[0],FilterType[1],FilterFieldName[2],FilterFieldValues[3],ActivationInterval[4],TTL[5],Limit[6],AllocationMessage[7],Weight[8],Thresholds[9] +#Id[0],FilterType[1],FilterFieldName[2],FilterFieldValues[3],ActivationInterval[4],TTL[5],Limit[6],AllocationMessage[7],Blocker[8],Stored[9],Weight[10],Thresholds[11] ResGroup1,*string,Account,1001;1002,2014-07-29T15:00:00Z,1s,7,,true,true,20, ResGroup1,*string_prefix,Destination,10;20,,,,,,,, ResGroup1,*rsr_fields,,Subject(~^1.*1$);Destination(1002),,,,,,,, diff --git a/data/tariffplans/tutorial/ResourceLimits.csv b/data/tariffplans/tutorial/ResourceLimits.csv index d29dbc52c..f18c3aae8 100755 --- a/data/tariffplans/tutorial/ResourceLimits.csv +++ b/data/tariffplans/tutorial/ResourceLimits.csv @@ -1,4 +1,4 @@ -#Id[0],FilterType[1],FilterFieldName[2],FilterFieldValues[3],ActivationInterval[4],TTL[5],Limit[6],AllocationMessage[7],Weight[8],Thresholds[9] +#Id[0],FilterType[1],FilterFieldName[2],FilterFieldValues[3],ActivationInterval[4],TTL[5],Limit[6],AllocationMessage[7],Blocker[8],Stored[9],Weight[10],Thresholds[11] ResGroup1,*string,Account,1001;1002,2014-07-29T15:00:00Z,1s,7,,true,true,20, ResGroup1,*string_prefix,Destination,10;20,,,,,,,, ResGroup1,*rsr_fields,,Subject(~^1.*1$);Destination(1002),,,,,,,, diff --git a/engine/cdr_test.go b/engine/cdr_test.go index 7d305ec87..2a645dd7e 100644 --- a/engine/cdr_test.go +++ b/engine/cdr_test.go @@ -502,11 +502,84 @@ func TestCDRParseFieldValue(t *testing.T) { } } +func TestCDRAsMapStringIface(t *testing.T) { + cdr := &CDR{ + CGRID: utils.Sha1("dsafdsaf", time.Date(2013, 11, 7, 8, 42, 26, 0, time.UTC).String()), + OrderID: 123, + ToR: utils.VOICE, + OriginID: "dsafdsaf", + OriginHost: "192.168.1.1", + Source: utils.UNIT_TEST, + RequestType: utils.META_RATED, + Direction: "*out", + Tenant: "cgrates.org", + Category: "call", + Account: "1002", + Subject: "1001", + Destination: "+4986517174963", + SetupTime: time.Date(2013, 11, 7, 8, 42, 20, 0, time.UTC), + AnswerTime: time.Date(2013, 11, 7, 8, 42, 26, 0, time.UTC), + RunID: utils.DEFAULT_RUNID, + Usage: time.Duration(10) * time.Second, + Supplier: "SUPPL1", + ExtraFields: map[string]string{"field_extr1": "val_extr1", "fieldextr2": "valextr2"}, + Cost: 1.01, + } + + mp := map[string]interface{}{ + "field_extr1": "val_extr1", + "fieldextr2": "valextr2", + utils.CGRID: cdr.CGRID, + utils.MEDI_RUNID: utils.DEFAULT_RUNID, + utils.ORDERID: cdr.OrderID, + utils.CDRHOST: "192.168.1.1", + utils.CDRSOURCE: utils.UNIT_TEST, + utils.ACCID: "dsafdsaf", + utils.TOR: utils.VOICE, + utils.REQTYPE: utils.META_RATED, + utils.DIRECTION: "*out", + utils.TENANT: "cgrates.org", + utils.CATEGORY: "call", + utils.ACCOUNT: "1002", + utils.SUBJECT: "1001", + utils.DESTINATION: "+4986517174963", + utils.SETUP_TIME: time.Date(2013, 11, 7, 8, 42, 20, 0, time.UTC), + utils.PDD: time.Duration(0) * time.Second, + utils.ANSWER_TIME: time.Date(2013, 11, 7, 8, 42, 26, 0, time.UTC), + utils.USAGE: time.Duration(10) * time.Second, + utils.SUPPLIER: "SUPPL1", + utils.DISCONNECT_CAUSE: cdr.DisconnectCause, + utils.CostSource: cdr.CostSource, + utils.COST: 1.01, + utils.COST_DETAILS: cdr.CostDetails, + utils.RATED: false, + utils.PartialField: false, + utils.ExtraInfo: cdr.ExtraInfo, + } + if cdrMp, err := cdr.AsMapStringIface(); err != nil { + t.Error(err) + } else if !reflect.DeepEqual(mp, cdrMp) { + t.Errorf("Expecting: %+v, received: %+v", mp, cdrMp) + } + +} + func TestCDRAsExportRecord(t *testing.T) { - cdr := &CDR{CGRID: utils.Sha1("dsafdsaf", time.Unix(1383813745, 0).UTC().String()), ToR: utils.VOICE, OriginID: "dsafdsaf", OriginHost: "192.168.1.1", - RequestType: utils.META_RATED, Direction: "*out", Tenant: "cgrates.org", - Category: "call", Account: "1001", Subject: "1001", Destination: "+4986517174963", SetupTime: time.Unix(1383813745, 0).UTC(), AnswerTime: time.Unix(1383813746, 0).UTC(), - Usage: time.Duration(10) * time.Second, RunID: utils.DEFAULT_RUNID, Cost: 1.01, + cdr := &CDR{ + CGRID: utils.Sha1("dsafdsaf", + time.Unix(1383813745, 0).UTC().String()), + ToR: utils.VOICE, OriginID: "dsafdsaf", + OriginHost: "192.168.1.1", + RequestType: utils.META_RATED, + Direction: "*out", Tenant: "cgrates.org", + Category: "call", + Account: "1001", + Subject: "1001", + Destination: "+4986517174963", + SetupTime: time.Unix(1383813745, 0).UTC(), + AnswerTime: time.Unix(1383813746, 0).UTC(), + Usage: time.Duration(10) * time.Second, + RunID: utils.DEFAULT_RUNID, Cost: 1.01, ExtraFields: map[string]string{"stop_time": "2014-06-11 19:19:00 +0000 UTC", "fieldextr2": "valextr2"}} val, _ := utils.ParseRSRFields(utils.DESTINATION, utils.INFIELD_SEP) diff --git a/engine/loader_csv_test.go b/engine/loader_csv_test.go index df4863fc6..138a777cf 100755 --- a/engine/loader_csv_test.go +++ b/engine/loader_csv_test.go @@ -1460,8 +1460,8 @@ func TestLoadStats(t *testing.T) { } func TestLoadThresholds(t *testing.T) { - eThresholds := map[string]*utils.TPThresholdCfg{ - "Threshold1": &utils.TPThresholdCfg{ + eThresholds := map[string]*utils.TPThreshold{ + "Threshold1": &utils.TPThreshold{ TPid: testTPID, ID: "Threshold1", Filters: []*utils.TPRequestFilter{ diff --git a/engine/model_helpers.go b/engine/model_helpers.go index 7e8c9ba2c..a664d7cad 100755 --- a/engine/model_helpers.go +++ b/engine/model_helpers.go @@ -2089,14 +2089,14 @@ func APItoStats(tpST *utils.TPStats, timezone string) (st *StatsQueue, err error return st, nil } -type TpThresholdCfgS []*TpThresholdCfg +type TpThresholdS []*TpThreshold -func (tps TpThresholdCfgS) AsTPThresholdCfg() (result []*utils.TPThresholdCfg) { - mst := make(map[string]*utils.TPThresholdCfg) +func (tps TpThresholdS) AsTPThreshold() (result []*utils.TPThreshold) { + mst := make(map[string]*utils.TPThreshold) for _, tp := range tps { th, found := mst[tp.Tag] if !found { - th = &utils.TPThresholdCfg{ + th = &utils.TPThreshold{ TPid: tp.Tpid, ID: tp.Tag, Blocker: tp.Blocker, @@ -2138,7 +2138,7 @@ func (tps TpThresholdCfgS) AsTPThresholdCfg() (result []*utils.TPThresholdCfg) { } mst[tp.Tag] = th } - result = make([]*utils.TPThresholdCfg, len(mst)) + result = make([]*utils.TPThreshold, len(mst)) i := 0 for _, th := range mst { result[i] = th @@ -2147,12 +2147,12 @@ func (tps TpThresholdCfgS) AsTPThresholdCfg() (result []*utils.TPThresholdCfg) { return } -func APItoModelTPThresholdCfg(th *utils.TPThresholdCfg) (mdls TpThresholdCfgS) { +func APItoModelTPThreshold(th *utils.TPThreshold) (mdls TpThresholdS) { if len(th.Filters) == 0 { return } for i, fltr := range th.Filters { - mdl := &TpThresholdCfg{ + mdl := &TpThreshold{ Tpid: th.TPid, Tag: th.ID, } @@ -2196,7 +2196,7 @@ func APItoModelTPThresholdCfg(th *utils.TPThresholdCfg) (mdls TpThresholdCfgS) { return } -func APItoThresholdCfg(tpTH *utils.TPThresholdCfg, timezone string) (th *ThresholdCfg, err error) { +func APItoThresholdCfg(tpTH *utils.TPThreshold, timezone string) (th *ThresholdCfg, err error) { th = &ThresholdCfg{ ID: tpTH.ID, ThresholdType: tpTH.ThresholdType, diff --git a/engine/model_helpers_test.go b/engine/model_helpers_test.go old mode 100644 new mode 100755 index 9a7274445..f47229662 --- a/engine/model_helpers_test.go +++ b/engine/model_helpers_test.go @@ -884,9 +884,9 @@ func TestAPItoTPStats(t *testing.T) { } } -func TestAsTPThresholdCfgAsAsTPThresholdCfg(t *testing.T) { - tps := []*TpThresholdCfg{ - &TpThresholdCfg{ +func TestAsTPThresholdAsAsTPThreshold(t *testing.T) { + tps := []*TpThreshold{ + &TpThreshold{ Tpid: "TEST_TPID", Tag: "Stats1", FilterType: MetaStringPrefix, @@ -904,8 +904,8 @@ func TestAsTPThresholdCfgAsAsTPThresholdCfg(t *testing.T) { ActionIDs: "WARN3", }, } - eTPs := []*utils.TPThresholdCfg{ - &utils.TPThresholdCfg{ + eTPs := []*utils.TPThreshold{ + &utils.TPThreshold{ TPid: tps[0].Tpid, ID: tps[0].Tag, Filters: []*utils.TPRequestFilter{ @@ -929,14 +929,14 @@ func TestAsTPThresholdCfgAsAsTPThresholdCfg(t *testing.T) { ActionIDs: []string{"WARN3"}, }, } - rcvTPs := TpThresholdCfgS(tps).AsTPThresholdCfg() + rcvTPs := TpThresholdS(tps).AsTPThreshold() if !(reflect.DeepEqual(eTPs, rcvTPs) || reflect.DeepEqual(eTPs[0], rcvTPs[0])) { t.Errorf("\nExpecting:\n%+v\nReceived:\n%+v", utils.ToIJSON(eTPs), utils.ToIJSON(rcvTPs)) } } -func TestAPItoTPThresholdCfg(t *testing.T) { - tps := &utils.TPThresholdCfg{ +func TestAPItoTPThreshold(t *testing.T) { + tps := &utils.TPThreshold{ TPid: testTPID, ID: "Stats1", Filters: []*utils.TPRequestFilter{ diff --git a/engine/models.go b/engine/models.go index 825f5777e..3be370d76 100755 --- a/engine/models.go +++ b/engine/models.go @@ -496,7 +496,7 @@ type TpStats struct { CreatedAt time.Time } -type TpThresholdCfg struct { +type TpThreshold struct { ID int64 Tpid string Tag string `index:"0" re:""` diff --git a/engine/storage_csv.go b/engine/storage_csv.go index 25fb6b143..26993e13a 100755 --- a/engine/storage_csv.go +++ b/engine/storage_csv.go @@ -648,8 +648,8 @@ func (csvs *CSVStorage) GetTPStats(tpid, id string) ([]*utils.TPStats, error) { return tpStats.AsTPStats(), nil } -func (csvs *CSVStorage) GetTPThresholdCfg(tpid, id string) ([]*utils.TPThresholdCfg, error) { - csvReader, fp, err := csvs.readerFunc(csvs.thresholdsFn, csvs.sep, getColumnCount(TpThresholdCfg{})) +func (csvs *CSVStorage) GetTPThreshold(tpid, id string) ([]*utils.TPThreshold, error) { + csvReader, fp, err := csvs.readerFunc(csvs.thresholdsFn, csvs.sep, getColumnCount(TpThreshold{})) if err != nil { //log.Print("Could not load stats file: ", err) // allow writing of the other values @@ -658,22 +658,22 @@ func (csvs *CSVStorage) GetTPThresholdCfg(tpid, id string) ([]*utils.TPThreshold if fp != nil { defer fp.Close() } - var tpThresholdCfg TpThresholdCfgS + var tpThreshold TpThresholdS for record, err := csvReader.Read(); err != io.EOF; record, err = csvReader.Read() { if err != nil { - log.Print("bad line in TPThresholdCfg csv: ", err) + log.Print("bad line in TPThreshold csv: ", err) return nil, err } - if thresholdCfg, err := csvLoad(TpThresholdCfg{}, record); err != nil { - log.Print("error loading TPThresholdCfg: ", err) + if thresholdCfg, err := csvLoad(TpThreshold{}, record); err != nil { + log.Print("error loading TPThreshold: ", err) return nil, err } else { - tHresholdCfg := thresholdCfg.(TpThresholdCfg) + tHresholdCfg := thresholdCfg.(TpThreshold) tHresholdCfg.Tpid = tpid - tpThresholdCfg = append(tpThresholdCfg, &tHresholdCfg) + tpThreshold = append(tpThreshold, &tHresholdCfg) } } - return tpThresholdCfg.AsTPThresholdCfg(), nil + return tpThreshold.AsTPThreshold(), nil } func (csvs *CSVStorage) GetTpIds() ([]string, error) { diff --git a/engine/storage_interface.go b/engine/storage_interface.go index a3a78b0d7..812dc24be 100755 --- a/engine/storage_interface.go +++ b/engine/storage_interface.go @@ -167,7 +167,7 @@ type LoadReader interface { GetTPAccountActions(*utils.TPAccountActions) ([]*utils.TPAccountActions, error) GetTPResourceLimits(string, string) ([]*utils.TPResourceLimit, error) GetTPStats(string, string) ([]*utils.TPStats, error) - GetTPThresholdCfg(string, string) ([]*utils.TPThresholdCfg, error) + GetTPThreshold(string, string) ([]*utils.TPThreshold, error) } type LoadWriter interface { @@ -190,7 +190,7 @@ type LoadWriter interface { SetTPAccountActions([]*utils.TPAccountActions) error SetTPResourceLimits([]*utils.TPResourceLimit) error SetTPStats([]*utils.TPStats) error - SetTPThresholdCfg([]*utils.TPThresholdCfg) error + SetTPThreshold([]*utils.TPThreshold) error } // NewMarshaler returns the marshaler type selected by mrshlerStr diff --git a/engine/storage_mongo_stordb.go b/engine/storage_mongo_stordb.go old mode 100644 new mode 100755 index 963e414e4..bfc9658d0 --- a/engine/storage_mongo_stordb.go +++ b/engine/storage_mongo_stordb.go @@ -1136,14 +1136,14 @@ func (ms *MongoStorage) SetTPStats(tpSTs []*utils.TPStats) (err error) { return } -func (ms *MongoStorage) GetTPThresholdCfg(tpid, id string) ([]*utils.TPThresholdCfg, error) { +func (ms *MongoStorage) GetTPThreshold(tpid, id string) ([]*utils.TPThreshold, error) { filter := bson.M{ "tpid": tpid, } if id != "" { filter["id"] = id } - var results []*utils.TPThresholdCfg + var results []*utils.TPThreshold session, col := ms.conn(utils.TBLTPThresholds) defer session.Close() err := col.Find(filter).All(&results) @@ -1153,7 +1153,7 @@ func (ms *MongoStorage) GetTPThresholdCfg(tpid, id string) ([]*utils.TPThreshold return results, err } -func (ms *MongoStorage) SetTPThresholdCfg(tpTHs []*utils.TPThresholdCfg) (err error) { +func (ms *MongoStorage) SetTPThreshold(tpTHs []*utils.TPThreshold) (err error) { if len(tpTHs) == 0 { return } diff --git a/engine/storage_sql.go b/engine/storage_sql.go old mode 100644 new mode 100755 index d363ea7b2..49e755f43 --- a/engine/storage_sql.go +++ b/engine/storage_sql.go @@ -602,18 +602,18 @@ func (self *SQLStorage) SetTPStats(sts []*utils.TPStats) error { return nil } -func (self *SQLStorage) SetTPThresholdCfg(ths []*utils.TPThresholdCfg) error { +func (self *SQLStorage) SetTPThreshold(ths []*utils.TPThreshold) error { if len(ths) == 0 { return nil } tx := self.db.Begin() for _, th := range ths { // Remove previous - if err := tx.Where(&TpThresholdCfg{Tpid: th.TPid, Tag: th.ID}).Delete(TpThresholdCfg{}).Error; err != nil { + if err := tx.Where(&TpThreshold{Tpid: th.TPid, Tag: th.ID}).Delete(TpThreshold{}).Error; err != nil { tx.Rollback() return err } - for _, mst := range APItoModelTPThresholdCfg(th) { + for _, mst := range APItoModelTPThreshold(th) { if err := tx.Save(&mst).Error; err != nil { tx.Rollback() return err @@ -1570,8 +1570,8 @@ func (self *SQLStorage) GetTPStats(tpid, id string) ([]*utils.TPStats, error) { return asts, nil } -func (self *SQLStorage) GetTPThresholdCfg(tpid, id string) ([]*utils.TPThresholdCfg, error) { - var ths TpThresholdCfgS +func (self *SQLStorage) GetTPThreshold(tpid, id string) ([]*utils.TPThreshold, error) { + var ths TpThresholdS q := self.db.Where("tpid = ?", tpid) if len(id) != 0 { q = q.Where("tag = ?", id) @@ -1579,7 +1579,7 @@ func (self *SQLStorage) GetTPThresholdCfg(tpid, id string) ([]*utils.TPThreshold if err := q.Find(&ths).Error; err != nil { return nil, err } - aths := ths.AsTPThresholdCfg() + aths := ths.AsTPThreshold() if len(aths) == 0 { return aths, utils.ErrNotFound } diff --git a/engine/tp_reader.go b/engine/tp_reader.go old mode 100644 new mode 100755 index 05ea76e21..0c3d00a9d --- a/engine/tp_reader.go +++ b/engine/tp_reader.go @@ -54,7 +54,7 @@ type TpReader struct { aliases map[string]*Alias resLimits map[string]*utils.TPResourceLimit stats map[string]*utils.TPStats - thresholds map[string]*utils.TPThresholdCfg + thresholds map[string]*utils.TPThreshold revDests, revAliases, @@ -128,7 +128,7 @@ func (tpr *TpReader) Init() { tpr.derivedChargers = make(map[string]*utils.DerivedChargers) tpr.resLimits = make(map[string]*utils.TPResourceLimit) tpr.stats = make(map[string]*utils.TPStats) - tpr.thresholds = make(map[string]*utils.TPThresholdCfg) + tpr.thresholds = make(map[string]*utils.TPThreshold) tpr.revDests = make(map[string][]string) tpr.revAliases = make(map[string][]string) tpr.acntActionPlans = make(map[string][]string) @@ -1626,11 +1626,11 @@ func (tpr *TpReader) LoadStats() error { } func (tpr *TpReader) LoadThresholdsFiltered(tag string) error { - tps, err := tpr.lr.GetTPThresholdCfg(tpr.tpid, tag) + tps, err := tpr.lr.GetTPThreshold(tpr.tpid, tag) if err != nil { return err } - mapTHs := make(map[string]*utils.TPThresholdCfg) + mapTHs := make(map[string]*utils.TPThreshold) for _, th := range tps { mapTHs[th.ID] = th } diff --git a/engine/tpimporter_csv.go b/engine/tpimporter_csv.go index 9c9416dae..f645612da 100755 --- a/engine/tpimporter_csv.go +++ b/engine/tpimporter_csv.go @@ -377,9 +377,9 @@ func (self *TPCSVImporter) importThresholds(fn string) error { if self.Verbose { log.Printf("Processing file: <%s> ", fn) } - sts, err := self.csvr.GetTPThresholdCfg(self.TPid, "") + sts, err := self.csvr.GetTPThreshold(self.TPid, "") if err != nil { return err } - return self.StorDb.SetTPThresholdCfg(sts) + return self.StorDb.SetTPThreshold(sts) } diff --git a/utils/apitpdata.go b/utils/apitpdata.go index 8e18920a8..740a34531 100755 --- a/utils/apitpdata.go +++ b/utils/apitpdata.go @@ -1344,7 +1344,7 @@ type TPStats struct { Thresholds []string } -type TPThresholdCfg struct { +type TPThreshold struct { TPid string ID string Filters []*TPRequestFilter // Filters for the request