Small fix

This commit is contained in:
edwardro22
2017-08-09 22:16:11 +03:00
parent ae54392a85
commit 602fb59aab
11 changed files with 46 additions and 46 deletions

View File

@@ -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{

View File

@@ -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,

16
engine/model_helpers_test.go Normal file → Executable file
View File

@@ -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{

View File

@@ -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:""`

View File

@@ -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) {

View File

@@ -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

6
engine/storage_mongo_stordb.go Normal file → Executable file
View File

@@ -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
}

12
engine/storage_sql.go Normal file → Executable file
View File

@@ -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
}

8
engine/tp_reader.go Normal file → Executable file
View File

@@ -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
}

View File

@@ -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)
}

View File

@@ -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