mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-23 16:18:44 +05:00
SessionSv1.ProcessEvent supporting *routes flag
This commit is contained in:
@@ -26,6 +26,7 @@ import (
|
||||
"github.com/cgrates/cgrates/attributes"
|
||||
"github.com/cgrates/cgrates/chargers"
|
||||
"github.com/cgrates/cgrates/engine"
|
||||
"github.com/cgrates/cgrates/routes"
|
||||
"github.com/cgrates/cgrates/utils"
|
||||
"github.com/cgrates/guardian"
|
||||
)
|
||||
@@ -100,7 +101,7 @@ func (sS *SessionS) BiRPCv1AuthorizeEvent(ctx *context.Context,
|
||||
rplyAttr, err := sS.processAttributes(ctx, args)
|
||||
if err == nil {
|
||||
args = rplyAttr.CGREvent
|
||||
authReply.Attributes = &rplyAttr
|
||||
authReply.Attributes = rplyAttr
|
||||
} else if err.Error() != utils.ErrNotFound.Error() {
|
||||
return utils.NewErrAttributeS(err)
|
||||
}
|
||||
@@ -329,7 +330,7 @@ func (sS *SessionS) BiRPCv1InitiateSession(ctx *context.Context,
|
||||
rplyAttr, err := sS.processAttributes(ctx, args)
|
||||
if err == nil {
|
||||
args = rplyAttr.CGREvent
|
||||
rply.Attributes = &rplyAttr
|
||||
rply.Attributes = rplyAttr
|
||||
} else if err.Error() != utils.ErrNotFound.Error() {
|
||||
return utils.NewErrAttributeS(err)
|
||||
}
|
||||
@@ -529,7 +530,7 @@ func (sS *SessionS) BiRPCv1UpdateSession(ctx *context.Context,
|
||||
rplyAttr, err := sS.processAttributes(ctx, args)
|
||||
if err == nil {
|
||||
args = rplyAttr.CGREvent
|
||||
rply.Attributes = &rplyAttr
|
||||
rply.Attributes = rplyAttr
|
||||
} else if err.Error() != utils.ErrNotFound.Error() {
|
||||
return utils.NewErrAttributeS(err)
|
||||
}
|
||||
@@ -844,7 +845,7 @@ func (sS *SessionS) BiRPCv1ProcessEvent(ctx *context.Context,
|
||||
}
|
||||
} else {
|
||||
*apiArgs = *rplyAttr.CGREvent
|
||||
apiRply.Attributes[utils.MetaDefault] = &rplyAttr
|
||||
apiRply.Attributes[utils.MetaDefault] = rplyAttr
|
||||
}
|
||||
}
|
||||
|
||||
@@ -895,12 +896,17 @@ func (sS *SessionS) BiRPCv1ProcessEvent(ctx *context.Context,
|
||||
return errRTs
|
||||
}
|
||||
utils.Logger.Warning(
|
||||
fmt.Sprintf("<%s> error: %s processing event: %+v with %s",
|
||||
fmt.Sprintf("<%s> error: %s processing event: %+v flag for %s",
|
||||
utils.SessionS, err.Error(), cgrEv, utils.RateS))
|
||||
} else if rtS {
|
||||
var rtsCost *utils.Decimal
|
||||
if rtsCost, err = sS.ratesCost(ctx, cgrEv); err != nil {
|
||||
return
|
||||
if cch[utils.OptsSesBlockerError].(bool) {
|
||||
return
|
||||
}
|
||||
utils.Logger.Warning(
|
||||
fmt.Sprintf("<%s> error: %s processing event: %+v with %s",
|
||||
utils.SessionS, err.Error(), cgrEv, utils.RateS))
|
||||
}
|
||||
if apiRply.RateSCost == nil {
|
||||
apiRply.RateSCost = make(map[string]float64)
|
||||
@@ -909,6 +915,32 @@ func (sS *SessionS) BiRPCv1ProcessEvent(ctx *context.Context,
|
||||
apiRply.RateSCost[runID] = costFlt
|
||||
}
|
||||
|
||||
// RouteS Enabled
|
||||
if rous, errRous := engine.GetBoolOpts(ctx, apiArgs.Tenant, apiArgs.AsDataProvider(), cchEv,
|
||||
sS.fltrS, sS.cfg.SessionSCfg().Opts.Routes,
|
||||
utils.MetaRoutes); errRous != nil {
|
||||
if cch[utils.OptsSesBlockerError].(bool) {
|
||||
return errRous
|
||||
}
|
||||
utils.Logger.Warning(
|
||||
fmt.Sprintf("<%s> error: %s processing event: %+v flag for %s",
|
||||
utils.SessionS, err.Error(), cgrEv, utils.RouteS))
|
||||
} else if rous {
|
||||
var rous routes.SortedRoutesList
|
||||
if rous, err = sS.getRoutes(ctx, cgrEv); err != nil {
|
||||
if cch[utils.OptsSesBlockerError].(bool) {
|
||||
return
|
||||
}
|
||||
utils.Logger.Warning(
|
||||
fmt.Sprintf("<%s> error: %s processing event: %+v with %s",
|
||||
utils.SessionS, err.Error(), cgrEv, utils.RouteS))
|
||||
}
|
||||
if apiRply.RouteProfiles == nil {
|
||||
apiRply.RouteProfiles = make(map[string]routes.SortedRoutesList)
|
||||
}
|
||||
apiRply.RouteProfiles[runID] = rous
|
||||
}
|
||||
|
||||
// IPs Enabled
|
||||
if ipS, errIPs := engine.GetBoolOpts(ctx, apiArgs.Tenant, apiArgs.AsDataProvider(), cchEv,
|
||||
sS.fltrS, sS.cfg.SessionSCfg().Opts.IPs,
|
||||
|
||||
@@ -999,7 +999,7 @@ func (sS *SessionS) resourcesAuthorize(ctx *context.Context, cgrEv *utils.CGREve
|
||||
// accountsMaxAbstracts will query the AccountS cost for Event
|
||||
func (sS *SessionS) accountsMaxAbstracts(ctx *context.Context, cgrEv *utils.CGREvent) (rply *utils.EventCharges, err error) {
|
||||
if len(sS.cfg.SessionSCfg().AccountSConns) == 0 {
|
||||
err = errors.New("AccountS is disabled")
|
||||
err = utils.NewErrNotConnected(utils.AccountS)
|
||||
return
|
||||
}
|
||||
var acntCost utils.EventCharges
|
||||
@@ -1013,7 +1013,7 @@ func (sS *SessionS) accountsMaxAbstracts(ctx *context.Context, cgrEv *utils.CGRE
|
||||
// ratesCost will query the RateS cost for Event
|
||||
func (sS *SessionS) ratesCost(ctx *context.Context, cgrEv *utils.CGREvent) (cost *utils.Decimal, err error) {
|
||||
if len(sS.cfg.SessionSCfg().RateSConns) == 0 {
|
||||
err = errors.New("RateS is disabled")
|
||||
err = utils.NewErrNotConnected(utils.RateS)
|
||||
return
|
||||
}
|
||||
var rtsCost utils.RateProfileCost
|
||||
@@ -2395,7 +2395,7 @@ func (sS *SessionS) processThreshold(ctx *context.Context, cgrEv *utils.CGREvent
|
||||
// processStats will receive the event and send it to StatS to be processed
|
||||
func (sS *SessionS) processStats(ctx *context.Context, cgrEv *utils.CGREvent, clnb bool) (sIDs []string, err error) {
|
||||
if len(sS.cfg.SessionSCfg().StatSConns) == 0 {
|
||||
return sIDs, utils.NewErrNotConnected(utils.StatS)
|
||||
return nil, utils.NewErrNotConnected(utils.StatS)
|
||||
}
|
||||
|
||||
cgrEv.SetCloneable(clnb)
|
||||
@@ -2407,7 +2407,7 @@ func (sS *SessionS) processStats(ctx *context.Context, cgrEv *utils.CGREvent, cl
|
||||
// getRoutes will receive the event and send it to SupplierS to find the suppliers
|
||||
func (sS *SessionS) getRoutes(ctx *context.Context, cgrEv *utils.CGREvent) (routesReply routes.SortedRoutesList, err error) {
|
||||
if len(sS.cfg.SessionSCfg().RouteSConns) == 0 {
|
||||
return routesReply, utils.NewErrNotConnected(utils.RouteS)
|
||||
return nil, utils.NewErrNotConnected(utils.RouteS)
|
||||
}
|
||||
if acd, has := cgrEv.Event[utils.ACD]; has {
|
||||
cgrEv.Event[utils.Usage] = acd
|
||||
@@ -2420,9 +2420,9 @@ func (sS *SessionS) getRoutes(ctx *context.Context, cgrEv *utils.CGREvent) (rout
|
||||
}
|
||||
|
||||
// processAttributes will receive the event and send it to AttributeS to be processed
|
||||
func (sS *SessionS) processAttributes(ctx *context.Context, cgrEv *utils.CGREvent) (rplyEv attributes.AttrSProcessEventReply, err error) {
|
||||
func (sS *SessionS) processAttributes(ctx *context.Context, cgrEv *utils.CGREvent) (rplyEv *attributes.AttrSProcessEventReply, err error) {
|
||||
if len(sS.cfg.SessionSCfg().AttributeSConns) == 0 {
|
||||
return rplyEv, utils.NewErrNotConnected(utils.AttributeS)
|
||||
return nil, utils.NewErrNotConnected(utils.AttributeS)
|
||||
}
|
||||
if cgrEv.APIOpts == nil {
|
||||
cgrEv.APIOpts = make(engine.MapEvent)
|
||||
|
||||
Reference in New Issue
Block a user