From f092d517dfe4cd9ef328c159d0ef75ad55c5f3fc Mon Sep 17 00:00:00 2001 From: DanB Date: Wed, 23 Jul 2014 19:53:52 +0200 Subject: [PATCH] MediatorV1.RateCdrs with more filter options, renaming cdr arguments to reflect plurals properly --- apier/cdre.go | 5 +- apier/cdrs.go | 4 +- apier/mediator.go | 6 ++- mediator/mediator.go | 6 ++- mediator/mediator_local_test.go | 4 +- utils/apitpdata.go | 90 +++++++++++++++++++-------------- 6 files changed, 70 insertions(+), 45 deletions(-) diff --git a/apier/cdre.go b/apier/cdre.go index d83244a61..f66da9e18 100644 --- a/apier/cdre.go +++ b/apier/cdre.go @@ -121,8 +121,9 @@ func (self *ApierV1) ExportCdrsToFile(attr utils.AttrExpFileCdrs, reply *utils.E if attr.MaskLength != nil { maskLen = *attr.MaskLength } - cdrs, err := self.CdrDb.GetStoredCdrs(attr.CgrIds, attr.MediationRunId, attr.TOR, attr.CdrHost, attr.CdrSource, attr.ReqType, attr.Direction, - attr.Tenant, attr.Category, attr.Account, attr.Subject, attr.DestinationPrefix, attr.RatedAccount, attr.RatedSubject, attr.OrderIdStart, attr.OrderIdEnd, tStart, tEnd, attr.SkipErrors, attr.SkipRated, false) + cdrs, err := self.CdrDb.GetStoredCdrs(attr.CgrIds, attr.MediationRunIds, attr.TORs, attr.CdrHosts, attr.CdrSources, attr.ReqTypes, attr.Directions, + attr.Tenants, attr.Categories, attr.Accounts, attr.Subjects, attr.DestinationPrefixes, attr.RatedAccounts, attr.RatedSubjects, attr.OrderIdStart, attr.OrderIdEnd, + tStart, tEnd, attr.SkipErrors, attr.SkipRated, false) if err != nil { return err } else if len(cdrs) == 0 { diff --git a/apier/cdrs.go b/apier/cdrs.go index eaee22aba..7aadaab9d 100644 --- a/apier/cdrs.go +++ b/apier/cdrs.go @@ -59,8 +59,8 @@ func (apier *ApierV1) GetCdrs(attrs utils.AttrGetCdrs, reply *[]*utils.CgrCdrOut return err } } - if cdrs, err := apier.CdrDb.GetStoredCdrs(attrs.CgrIds, attrs.MediationRunId, attrs.TOR, attrs.CdrHost, attrs.CdrSource, attrs.ReqType, attrs.Direction, - attrs.Tenant, attrs.Category, attrs.Account, attrs.Subject, attrs.DestinationPrefix, attrs.RatedAccount, attrs.RatedSubject, + if cdrs, err := apier.CdrDb.GetStoredCdrs(attrs.CgrIds, attrs.MediationRunIds, attrs.TORs, attrs.CdrHosts, attrs.CdrSources, attrs.ReqTypes, attrs.Directions, + attrs.Tenants, attrs.Categories, attrs.Accounts, attrs.Subjects, attrs.DestinationPrefixes, attrs.RatedAccounts, attrs.RatedSubjects, attrs.OrderIdStart, attrs.OrderIdEnd, tStart, tEnd, attrs.SkipErrors, attrs.SkipRated, false); err != nil { return fmt.Errorf("%s:%s", utils.ERR_SERVER_ERROR, err.Error()) } else { diff --git a/apier/mediator.go b/apier/mediator.go index 618959beb..86a98a2b0 100644 --- a/apier/mediator.go +++ b/apier/mediator.go @@ -46,7 +46,11 @@ func (self *MediatorV1) RateCdrs(attrs utils.AttrRateCdrs, reply *string) error return err } } - if err := self.Medi.RateCdrs(tStart, tEnd, attrs.RerateErrors, attrs.RerateRated); err != nil { + //RateCdrs(cgrIds, runIds, tors, cdrHosts, cdrSources, reqTypes, directions, tenants, categories, accounts, subjects, destPrefixes []string, + //orderIdStart, orderIdEnd int64, timeStart, timeEnd time.Time, rerateErrors, rerateRated bool) + if err := self.Medi.RateCdrs(attrs.CgrIds, attrs.MediationRunIds, attrs.TORs, attrs.CdrHosts, attrs.CdrSources, attrs.ReqTypes, attrs.Directions, + attrs.Tenants, attrs.Categories, attrs.Accounts, attrs.Subjects, attrs.DestinationPrefixes, attrs.RatedAccounts, attrs.RatedSubjects, + attrs.OrderIdStart, attrs.OrderIdEnd, tStart, tEnd, attrs.RerateErrors, attrs.RerateRated); err != nil { return fmt.Errorf("%s:%s", utils.ERR_SERVER_ERROR, err.Error()) } *reply = utils.OK diff --git a/mediator/mediator.go b/mediator/mediator.go index d006dc6bf..d2ee4250a 100644 --- a/mediator/mediator.go +++ b/mediator/mediator.go @@ -163,8 +163,10 @@ func (self *Mediator) RateCdr(storedCdr *utils.StoredCdr) error { return nil } -func (self *Mediator) RateCdrs(timeStart, timeEnd time.Time, rerateErrors, rerateRated bool) error { - cdrs, err := self.cdrDb.GetStoredCdrs(nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, 0, 0, timeStart, timeEnd, !rerateErrors, !rerateRated, true) +func (self *Mediator) RateCdrs(cgrIds, runIds, tors, cdrHosts, cdrSources, reqTypes, directions, tenants, categories, accounts, subjects, destPrefixes, ratedAccounts, ratedSubjects []string, + orderIdStart, orderIdEnd int64, timeStart, timeEnd time.Time, rerateErrors, rerateRated bool) error { + cdrs, err := self.cdrDb.GetStoredCdrs(cgrIds, runIds, tors, cdrHosts, cdrSources, reqTypes, directions, tenants, categories, accounts, subjects, destPrefixes, ratedAccounts, ratedSubjects, + orderIdStart, orderIdEnd, timeStart, timeEnd, !rerateErrors, !rerateRated, true) if err != nil { return err } diff --git a/mediator/mediator_local_test.go b/mediator/mediator_local_test.go index 6bbdc1415..1ef344a5b 100644 --- a/mediator/mediator_local_test.go +++ b/mediator/mediator_local_test.go @@ -23,6 +23,7 @@ import ( "fmt" "net/http" "net/rpc" + "net/rpc/jsonrpc" "net/url" "os/exec" "path" @@ -127,7 +128,8 @@ func TestRpcConn(t *testing.T) { return } var err error - cgrRpc, err = rpc.Dial("tcp", cfg.RPCGOBListen) //ToDo: Fix with automatic config + //cgrRpc, err = rpc.Dial("tcp", cfg.RPCGOBListen) //ToDo: Fix with automatic config + cgrRpc, err = jsonrpc.Dial("tcp", cfg.RPCJSONListen) if err != nil { t.Fatal("Could not connect to CGR GOB-RPC Server: ", err.Error()) } diff --git a/utils/apitpdata.go b/utils/apitpdata.go index 3c2186b1a..5d9998924 100644 --- a/utils/apitpdata.go +++ b/utils/apitpdata.go @@ -340,19 +340,19 @@ type AttrExpFileCdrs struct { MaskDestinationId *string // Overwrite configured MaskDestId MaskLength *int // Overwrite configured MaskLength, -1 to use general config ones CgrIds []string // If provided, it will filter based on the cgrids present in list - MediationRunId []string // If provided, it will filter on mediation runid - TOR []string // If provided, filter on TypeOfRecord - CdrHost []string // If provided, it will filter cdrhost - CdrSource []string // If provided, it will filter cdrsource - ReqType []string // If provided, it will fiter reqtype - Direction []string // If provided, it will fiter direction - Tenant []string // If provided, it will filter tenant - Category []string // If provided, it will filter çategory - Account []string // If provided, it will filter account - Subject []string // If provided, it will filter the rating subject - DestinationPrefix []string // If provided, it will filter on destination prefix - RatedAccount []string // If provided, it will filter ratedaccount - RatedSubject []string // If provided, it will filter the ratedsubject + MediationRunIds []string // If provided, it will filter on mediation runid + TORs []string // If provided, filter on TypeOfRecord + CdrHosts []string // If provided, it will filter cdrhost + CdrSources []string // If provided, it will filter cdrsource + ReqTypes []string // If provided, it will fiter reqtype + Directions []string // If provided, it will fiter direction + Tenants []string // If provided, it will filter tenant + Categories []string // If provided, it will filter çategory + Accounts []string // If provided, it will filter account + Subjects []string // If provided, it will filter the rating subject + DestinationPrefixes []string // If provided, it will filter on destination prefix + RatedAccounts []string // If provided, it will filter ratedaccount + RatedSubjects []string // If provided, it will filter the ratedsubject OrderIdStart int64 // Export from this order identifier OrderIdEnd int64 // Export smaller than this order identifier TimeStart string // If provided, it will represent the starting of the CDRs interval (>=) @@ -372,26 +372,26 @@ type ExportedFileCdrs struct { } type AttrGetCdrs struct { - CgrIds []string // If provided, it will filter based on the cgrids present in list - MediationRunId []string // If provided, it will filter on mediation runid - TOR []string // If provided, filter on TypeOfRecord - CdrHost []string // If provided, it will filter cdrhost - CdrSource []string // If provided, it will filter cdrsource - ReqType []string // If provided, it will fiter reqtype - Direction []string // If provided, it will fiter direction - Tenant []string // If provided, it will filter tenant - Category []string // If provided, it will filter çategory - Account []string // If provided, it will filter account - Subject []string // If provided, it will filter the rating subject - DestinationPrefix []string // If provided, it will filter on destination prefix - RatedAccount []string // If provided, it will filter ratedaccount - RatedSubject []string // If provided, it will filter the ratedsubject - OrderIdStart int64 // Export from this order identifier - OrderIdEnd int64 // Export smaller than this order identifier - TimeStart string // If provided, it will represent the starting of the CDRs interval (>=) - TimeEnd string // If provided, it will represent the end of the CDRs interval (<) - SkipErrors bool // Do not export errored CDRs - SkipRated bool // Do not export rated CDRs + CgrIds []string // If provided, it will filter based on the cgrids present in list + MediationRunIds []string // If provided, it will filter on mediation runid + TORs []string // If provided, filter on TypeOfRecord + CdrHosts []string // If provided, it will filter cdrhost + CdrSources []string // If provided, it will filter cdrsource + ReqTypes []string // If provided, it will fiter reqtype + Directions []string // If provided, it will fiter direction + Tenants []string // If provided, it will filter tenant + Categories []string // If provided, it will filter çategory + Accounts []string // If provided, it will filter account + Subjects []string // If provided, it will filter the rating subject + DestinationPrefixes []string // If provided, it will filter on destination prefix + RatedAccounts []string // If provided, it will filter ratedaccount + RatedSubjects []string // If provided, it will filter the ratedsubject + OrderIdStart int64 // Export from this order identifier + OrderIdEnd int64 // Export smaller than this order identifier + TimeStart string // If provided, it will represent the starting of the CDRs interval (>=) + TimeEnd string // If provided, it will represent the end of the CDRs interval (<) + SkipErrors bool // Do not export errored CDRs + SkipRated bool // Do not export rated CDRs } type AttrRemCdrs struct { @@ -399,10 +399,26 @@ type AttrRemCdrs struct { } type AttrRateCdrs struct { - TimeStart string // Cdrs time start - TimeEnd string // Cdrs time end - RerateErrors bool // Rerate previous CDRs with errors (makes sense for reqtype rated and pseudoprepaid - RerateRated bool // Rerate CDRs which were previously rated (makes sense for reqtype rated and pseudoprepaid) + CgrIds []string // If provided, it will filter based on the cgrids present in list + MediationRunIds []string // If provided, it will filter on mediation runid + TORs []string // If provided, filter on TypeOfRecord + CdrHosts []string // If provided, it will filter cdrhost + CdrSources []string // If provided, it will filter cdrsource + ReqTypes []string // If provided, it will fiter reqtype + Directions []string // If provided, it will fiter direction + Tenants []string // If provided, it will filter tenant + Categories []string // If provided, it will filter çategory + Accounts []string // If provided, it will filter account + Subjects []string // If provided, it will filter the rating subject + DestinationPrefixes []string // If provided, it will filter on destination prefix + RatedAccounts []string // If provided, it will filter ratedaccount + RatedSubjects []string // If provided, it will filter the ratedsubject + OrderIdStart int64 // Export from this order identifier + OrderIdEnd int64 // Export smaller than this order identifier + TimeStart string // If provided, it will represent the starting of the CDRs interval (>=) + TimeEnd string // If provided, it will represent the end of the CDRs interval (<) + RerateErrors bool // Rerate previous CDRs with errors (makes sense for reqtype rated and pseudoprepaid + RerateRated bool // Rerate CDRs which were previously rated (makes sense for reqtype rated and pseudoprepaid) } type AttrLoadTpFromFolder struct {