mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-23 16:18:44 +05:00
CDRS forking rated CDRs depending on smg_costs, smg_costs indexing update to include origin_id also
This commit is contained in:
@@ -80,7 +80,6 @@ func (self *SMGSession) debitLoop(debitInterval time.Duration) {
|
||||
func (self *SMGSession) debit(dur time.Duration, lastUsed time.Duration) (time.Duration, error) {
|
||||
requestedDuration := dur
|
||||
self.totalUsage += lastUsed // Should reflect the total usage so far
|
||||
|
||||
//utils.Logger.Debug(fmt.Sprintf("ExtraDuration: %d", self.extraDuration))
|
||||
if lastUsed > 0 {
|
||||
self.extraDuration = self.lastUsage - lastUsed
|
||||
@@ -221,7 +220,8 @@ func (self *SMGSession) disconnectSession(reason string) error {
|
||||
}
|
||||
|
||||
// Merge the sum of costs and sends it to CDRS for storage
|
||||
func (self *SMGSession) saveOperations() error {
|
||||
// originID could have been changed from original event, hence passing as argument here
|
||||
func (self *SMGSession) saveOperations(originID string) error {
|
||||
if len(self.callCosts) == 0 {
|
||||
return nil // There are no costs to save, ignore the operation
|
||||
}
|
||||
@@ -243,7 +243,8 @@ func (self *SMGSession) saveOperations() error {
|
||||
CostSource: utils.SESSION_MANAGER_SOURCE,
|
||||
RunID: self.runId,
|
||||
OriginHost: self.eventStart.GetOriginatorIP(utils.META_DEFAULT),
|
||||
OriginID: self.eventStart.GetUUID(),
|
||||
OriginID: originID,
|
||||
Usage: self.TotalUsage().Seconds(),
|
||||
CostDetails: firstCC,
|
||||
}
|
||||
if err := self.cdrsrv.StoreSMCost(engine.AttrCDRSStoreSMCost{SMCost: smCost, CheckDuplicate: true}, &reply); err != nil {
|
||||
|
||||
@@ -143,7 +143,7 @@ func (self *SMGeneric) sessionEnd(sessionId string, usage time.Duration) error {
|
||||
if err := s.close(aTime.Add(usage)); err != nil {
|
||||
utils.Logger.Err(fmt.Sprintf("<SMGeneric> Could not close session: %s, runId: %s, error: %s", sessionId, s.runId, err.Error()))
|
||||
}
|
||||
if err := s.saveOperations(); err != nil {
|
||||
if err := s.saveOperations(sessionId); err != nil {
|
||||
utils.Logger.Err(fmt.Sprintf("<SMGeneric> Could not save session: %s, runId: %s, error: %s", sessionId, s.runId, err.Error()))
|
||||
}
|
||||
}
|
||||
@@ -228,8 +228,7 @@ func (self *SMGeneric) SessionUpdate(gev SMGenericEvent, clnt *rpc2.Client) (tim
|
||||
}
|
||||
return nilDuration, err
|
||||
}
|
||||
evUuid := gev.GetUUID()
|
||||
for _, s := range self.getSession(evUuid) {
|
||||
for _, s := range self.getSession(gev.GetUUID()) {
|
||||
if maxDur, err := s.debit(evMaxUsage, evLastUsed); err != nil {
|
||||
return nilDuration, err
|
||||
} else if maxDur < evMaxUsage {
|
||||
@@ -254,15 +253,18 @@ func (self *SMGeneric) SessionEnd(gev SMGenericEvent, clnt *rpc2.Client) error {
|
||||
if err == utils.ErrNotFound { // Session was already relocated, create a new session with this update
|
||||
err = self.sessionStart(gev, getClientConnId(clnt))
|
||||
}
|
||||
if err != nil {
|
||||
if err != nil && err != utils.ErrMandatoryIeMissing {
|
||||
return err
|
||||
}
|
||||
}
|
||||
sessionIDs := []string{gev.GetUUID()}
|
||||
if sessionIDPrefix, err := gev.GetFieldAsString(utils.OriginIDPrefix); err == nil { // OriginIDPrefix is present, OriginID will not be anymore considered
|
||||
sessionIDs = self.getSessionIDsForPrefix(sessionIDPrefix)
|
||||
}
|
||||
usage, err := gev.GetUsage(utils.META_DEFAULT)
|
||||
if err != nil {
|
||||
if err != utils.ErrNotFound {
|
||||
return err
|
||||
|
||||
}
|
||||
lastUsed, err := gev.GetLastUsed(utils.META_DEFAULT)
|
||||
if err != nil {
|
||||
@@ -272,18 +274,19 @@ func (self *SMGeneric) SessionEnd(gev SMGenericEvent, clnt *rpc2.Client) error {
|
||||
return err
|
||||
}
|
||||
var s *SMGSession
|
||||
for _, s = range self.getSession(gev.GetUUID()) {
|
||||
break
|
||||
for _, sID := range sessionIDs {
|
||||
for _, s = range self.getSession(sID) {
|
||||
break
|
||||
}
|
||||
if s != nil {
|
||||
break
|
||||
}
|
||||
}
|
||||
if s == nil {
|
||||
return nil
|
||||
}
|
||||
usage = s.TotalUsage() + lastUsed
|
||||
}
|
||||
sessionIDs := []string{gev.GetUUID()}
|
||||
if sessionIDPrefix, err := gev.GetFieldAsString(utils.OriginIDPrefix); err == nil { // OriginIDPrefix is present, OriginID will not be anymore considered
|
||||
sessionIDs = self.getSessionIDsForPrefix(sessionIDPrefix)
|
||||
}
|
||||
var interimError error
|
||||
for _, sessionID := range sessionIDs {
|
||||
if err := self.sessionEnd(sessionID, usage); err != nil {
|
||||
@@ -377,7 +380,6 @@ func (self *SMGeneric) ChargeEvent(gev SMGenericEvent, clnt *rpc2.Client) (maxDu
|
||||
utils.Logger.Err(fmt.Sprintf("<SM> ERROR failed to refund rounding: %v", err))
|
||||
}
|
||||
}
|
||||
|
||||
var reply string
|
||||
smCost := &engine.SMCost{
|
||||
CGRID: gev.GetCgrId(self.timezone),
|
||||
|
||||
Reference in New Issue
Block a user