mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-11 18:16:24 +05:00
Paginator for GetLcr requests
This commit is contained in:
@@ -32,7 +32,7 @@ func (self *ApierV1) GetLcr(lcrReq engine.LcrRequest, lcrReply *engine.LcrReply)
|
||||
return err
|
||||
}
|
||||
var lcrQried engine.LCRCost
|
||||
if err := self.Responder.GetLCR(cd, &lcrQried); err != nil {
|
||||
if err := self.Responder.GetLCR(&engine.AttrGetLcr{CallDescriptor: cd, Paginator: lcrReq.Paginator}, &lcrQried); err != nil {
|
||||
return utils.NewErrServerError(err)
|
||||
}
|
||||
if lcrQried.Entry == nil {
|
||||
@@ -62,7 +62,7 @@ func (self *ApierV1) GetLcrSuppliers(lcrReq engine.LcrRequest, suppliers *string
|
||||
return err
|
||||
}
|
||||
var lcrQried engine.LCRCost
|
||||
if err := self.Responder.GetLCR(cd, &lcrQried); err != nil {
|
||||
if err := self.Responder.GetLCR(&engine.AttrGetLcr{CallDescriptor: cd, Paginator: lcrReq.Paginator}, &lcrQried); err != nil {
|
||||
return utils.NewErrServerError(err)
|
||||
}
|
||||
if lcrQried.HasErrors() {
|
||||
|
||||
@@ -56,6 +56,7 @@ type LcrRequest struct {
|
||||
Destination string
|
||||
StartTime string
|
||||
Duration string
|
||||
*utils.Paginator
|
||||
}
|
||||
|
||||
func (self *LcrRequest) AsCallDescriptor() (*CallDescriptor, error) {
|
||||
|
||||
@@ -40,6 +40,11 @@ type SessionRun struct {
|
||||
CallCosts []*CallCost
|
||||
}
|
||||
|
||||
type AttrGetLcr struct {
|
||||
*CallDescriptor
|
||||
*utils.Paginator
|
||||
}
|
||||
|
||||
type Responder struct {
|
||||
Bal *balancer2go.Balancer
|
||||
ExitChan chan bool
|
||||
@@ -325,17 +330,17 @@ func (rs *Responder) LogCallCost(ccl *CallCostLog, reply *string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (rs *Responder) GetLCR(cd *CallDescriptor, reply *LCRCost) error {
|
||||
if cd.Subject == "" {
|
||||
cd.Subject = cd.Account
|
||||
func (rs *Responder) GetLCR(attrs *AttrGetLcr, reply *LCRCost) error {
|
||||
if attrs.CallDescriptor.Subject == "" {
|
||||
attrs.CallDescriptor.Subject = attrs.CallDescriptor.Account
|
||||
}
|
||||
if upData, err := LoadUserProfile(cd, "ExtraFields"); err != nil {
|
||||
if upData, err := LoadUserProfile(attrs.CallDescriptor, "ExtraFields"); err != nil {
|
||||
return err
|
||||
} else {
|
||||
udRcv := upData.(*CallDescriptor)
|
||||
*cd = *udRcv
|
||||
*attrs.CallDescriptor = *udRcv
|
||||
}
|
||||
lcrCost, err := cd.GetLCR(rs.Stats, nil)
|
||||
lcrCost, err := attrs.CallDescriptor.GetLCR(rs.Stats, attrs.Paginator)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -505,7 +510,7 @@ type Connector interface {
|
||||
GetSessionRuns(*StoredCdr, *[]*SessionRun) error
|
||||
ProcessCdr(*StoredCdr, *string) error
|
||||
LogCallCost(*CallCostLog, *string) error
|
||||
GetLCR(*CallDescriptor, *LCRCost) error
|
||||
GetLCR(*AttrGetLcr, *LCRCost) error
|
||||
}
|
||||
|
||||
type RPCClientConnector struct {
|
||||
@@ -552,6 +557,6 @@ func (rcc *RPCClientConnector) LogCallCost(ccl *CallCostLog, reply *string) erro
|
||||
return rcc.Client.Call("CDRSV1.LogCallCost", ccl, reply)
|
||||
}
|
||||
|
||||
func (rcc *RPCClientConnector) GetLCR(cd *CallDescriptor, reply *LCRCost) error {
|
||||
return rcc.Client.Call("Responder.GetLCR", cd, reply)
|
||||
func (rcc *RPCClientConnector) GetLCR(attrs *AttrGetLcr, reply *LCRCost) error {
|
||||
return rcc.Client.Call("Responder.GetLCR", attrs, reply)
|
||||
}
|
||||
|
||||
@@ -395,7 +395,7 @@ func TestGetLCR(t *testing.T) {
|
||||
},
|
||||
}
|
||||
var lcr LCRCost
|
||||
if err := rsponder.GetLCR(cdStatic, &lcr); err != nil {
|
||||
if err := rsponder.GetLCR(&AttrGetLcr{CallDescriptor: cdStatic}, &lcr); err != nil {
|
||||
t.Error(err)
|
||||
} else if !reflect.DeepEqual(eStLcr.Entry, lcr.Entry) {
|
||||
t.Errorf("Expecting: %+v, received: %+v", eStLcr.Entry, lcr.Entry)
|
||||
@@ -422,7 +422,7 @@ func TestGetLCR(t *testing.T) {
|
||||
},
|
||||
}
|
||||
var lcrLc LCRCost
|
||||
if err := rsponder.GetLCR(cdLowestCost, &lcrLc); err != nil {
|
||||
if err := rsponder.GetLCR(&AttrGetLcr{CallDescriptor: cdLowestCost}, &lcrLc); err != nil {
|
||||
t.Error(err)
|
||||
} else if !reflect.DeepEqual(eLcLcr.Entry, lcrLc.Entry) {
|
||||
t.Errorf("Expecting: %+v, received: %+v", eLcLcr.Entry, lcrLc.Entry)
|
||||
@@ -447,7 +447,7 @@ func TestGetLCR(t *testing.T) {
|
||||
&LCRSupplierCost{Supplier: "*out:tenant12:call:dan12", Cost: 0.6, Duration: 60 * time.Second},
|
||||
},
|
||||
}
|
||||
if err := rsponder.GetLCR(cdLowestCost, &lcrLc); err != nil {
|
||||
if err := rsponder.GetLCR(&AttrGetLcr{CallDescriptor: cdLowestCost}, &lcrLc); err != nil {
|
||||
t.Error(err)
|
||||
} else if !reflect.DeepEqual(eLcLcr.Entry, lcrLc.Entry) {
|
||||
t.Errorf("Expecting: %+v, received: %+v", eLcLcr.Entry, lcrLc.Entry)
|
||||
@@ -476,7 +476,7 @@ func TestGetLCR(t *testing.T) {
|
||||
},
|
||||
}
|
||||
var lcrQT LCRCost
|
||||
if err := rsponder.GetLCR(cdQosThreshold, &lcrQT); err != nil {
|
||||
if err := rsponder.GetLCR(&AttrGetLcr{CallDescriptor: cdQosThreshold}, &lcrQT); err != nil {
|
||||
t.Error(err)
|
||||
} else if !reflect.DeepEqual(eQTLcr.Entry, lcrQT.Entry) {
|
||||
t.Errorf("Expecting: %+v, received: %+v", eQTLcr.Entry, lcrQT.Entry)
|
||||
@@ -495,7 +495,7 @@ func TestGetLCR(t *testing.T) {
|
||||
&LCRSupplierCost{Supplier: "*out:tenant12:call:dan12", Cost: 0.6, Duration: 60 * time.Second, QOS: map[string]float64{PDD: -1, ACD: 300, TCD: 300, ASR: 100, ACC: 2, TCC: 2, DDC: 2}, qosSortParams: []string{"35", "4m"}},
|
||||
},
|
||||
}
|
||||
if err := rsponder.GetLCR(cdQosThreshold, &lcrQT); err != nil {
|
||||
if err := rsponder.GetLCR(&AttrGetLcr{CallDescriptor: cdQosThreshold}, &lcrQT); err != nil {
|
||||
t.Error(err)
|
||||
} else if !reflect.DeepEqual(eQTLcr.Entry, lcrQT.Entry) {
|
||||
t.Errorf("Expecting: %+v, received: %+v", eQTLcr.Entry, lcrQT.Entry)
|
||||
@@ -524,7 +524,7 @@ func TestGetLCR(t *testing.T) {
|
||||
},
|
||||
}
|
||||
var lcrQ LCRCost
|
||||
if err := rsponder.GetLCR(cdQos, &lcrQ); err != nil {
|
||||
if err := rsponder.GetLCR(&AttrGetLcr{CallDescriptor: cdQos}, &lcrQ); err != nil {
|
||||
t.Error(err)
|
||||
} else if !reflect.DeepEqual(eQosLcr.Entry, lcrQ.Entry) {
|
||||
t.Errorf("Expecting: %+v, received: %+v", eQosLcr.Entry, lcrQ.Entry)
|
||||
|
||||
@@ -193,7 +193,7 @@ func (sm *FSSessionManager) setCgrLcr(ev engine.Event, connId string) error {
|
||||
TimeStart: startTime,
|
||||
TimeEnd: startTime.Add(config.CgrConfig().MaxCallDuration),
|
||||
}
|
||||
if err := sm.rater.GetLCR(cd, &lcrCost); err != nil {
|
||||
if err := sm.rater.GetLCR(&engine.AttrGetLcr{CallDescriptor: cd}, &lcrCost); err != nil {
|
||||
return err
|
||||
}
|
||||
supps := []string{}
|
||||
@@ -238,7 +238,7 @@ func (sm *FSSessionManager) onChannelPark(ev engine.Event, connId string) {
|
||||
return
|
||||
}
|
||||
var lcr engine.LCRCost
|
||||
if err = sm.Rater().GetLCR(cd, &lcr); err != nil {
|
||||
if err = sm.Rater().GetLCR(&engine.AttrGetLcr{CallDescriptor: cd}, &lcr); err != nil {
|
||||
engine.Logger.Info(fmt.Sprintf("<SM-FreeSWITCH> LCR_API_ERROR: %s", err.Error()))
|
||||
sm.unparkCall(ev.GetUUID(), connId, ev.GetCallDestNr(utils.META_DEFAULT), SYSTEM_ERROR)
|
||||
}
|
||||
|
||||
@@ -106,7 +106,7 @@ func (self *KamailioSessionManager) getSuppliers(kev KamEvent) (string, error) {
|
||||
return "", errors.New("LCR_PREPROCESS_ERROR")
|
||||
}
|
||||
var lcr engine.LCRCost
|
||||
if err = self.Rater().GetLCR(cd, &lcr); err != nil {
|
||||
if err = self.Rater().GetLCR(&engine.AttrGetLcr{CallDescriptor: cd}, &lcr); err != nil {
|
||||
engine.Logger.Info(fmt.Sprintf("<SM-Kamailio> LCR_API_ERROR error: %s", err.Error()))
|
||||
return "", errors.New("LCR_API_ERROR")
|
||||
}
|
||||
|
||||
@@ -99,7 +99,7 @@ func (mc *MockConnector) GetDerivedMaxSessionTime(*engine.StoredCdr, *float64) e
|
||||
func (mc *MockConnector) GetSessionRuns(*engine.StoredCdr, *[]*engine.SessionRun) error { return nil }
|
||||
func (mc *MockConnector) ProcessCdr(*engine.StoredCdr, *string) error { return nil }
|
||||
func (mc *MockConnector) LogCallCost(*engine.CallCostLog, *string) error { return nil }
|
||||
func (mc *MockConnector) GetLCR(*engine.CallDescriptor, *engine.LCRCost) error { return nil }
|
||||
func (mc *MockConnector) GetLCR(*engine.AttrGetLcr, *engine.LCRCost) error { return nil }
|
||||
|
||||
func TestSessionRefund(t *testing.T) {
|
||||
mc := &MockConnector{}
|
||||
|
||||
Reference in New Issue
Block a user