mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-24 08:38:45 +05:00
Merge branch 'master' of github.com:cgrates/cgrates
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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{
|
||||
|
||||
@@ -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,
|
||||
|
||||
16
engine/model_helpers_test.go
Normal file → Executable file
16
engine/model_helpers_test.go
Normal file → Executable file
@@ -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{
|
||||
|
||||
@@ -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:""`
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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
6
engine/storage_mongo_stordb.go
Normal file → Executable 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
12
engine/storage_sql.go
Normal file → Executable 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
8
engine/tp_reader.go
Normal file → Executable 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
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user