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 e59be5f4e..d707e3ad1 100755 --- a/engine/model_helpers.go +++ b/engine/model_helpers.go @@ -2090,14 +2090,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, @@ -2139,7 +2139,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 @@ -2148,12 +2148,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, } @@ -2197,7 +2197,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 e6b26d787..0ee96e1a9 --- a/engine/model_helpers_test.go +++ b/engine/model_helpers_test.go @@ -885,9 +885,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, @@ -905,8 +905,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{ @@ -930,14 +930,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 04d0af530..d00c064fa 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 01a1140b6..16da141e4 --- 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