diff --git a/rates/rates.go b/rates/rates.go index 90389db36..9a6e059bf 100644 --- a/rates/rates.go +++ b/rates/rates.go @@ -38,6 +38,7 @@ func NewRateS(cfg *config.CGRConfig, filterS *engine.FilterS) *RateS { type RateS struct { cfg *config.CGRConfig filterS *engine.FilterS + dm *engine.DataManager } // ListenAndServe keeps the service alive @@ -67,7 +68,63 @@ func (rS *RateS) Call(serviceMethod string, args interface{}, reply interface{}) return utils.RPCCall(rS, serviceMethod, args, reply) } -// V1CostForEvent will be called to calculate the cost for an event -func (rS *RateS) V1CostForEvent(cgrEv *utils.CGREventWithOpts, rply *string) (err error) { +/* +// matchingRateProfileForEvent returns the matched RateProfile for the given event +func (rS *RateS) matchingRateProfileForEvent(cgrEv *utils.CGREvent) (rtPfl *RateProfile, err error) { + var rPrfIDs []string + if rPrfIDs, err = engine.MatchingItemIDsForEvent( + cgrEv.Event, + rS.cfg.RateSCfg().StringIndexedFields, + rS.cfg.RateSCfg().PrefixIndexedFields, + rS.dm, utils.CacheRateProfilesFilterIndexes, + cgrEv.Tenant, + rpS.cgrcfg.RouteSCfg().IndexedSelects, + rpS.cgrcfg.RouteSCfg().NestedFields, + ); err != nil { + return + } + evNm := utils.MapStorage{utils.MetaReq: ev.Event} + for lpID := range rPrfIDs { + rPrf, err := rpS.dm.GetRouteProfile(ev.Tenant, lpID, true, true, utils.NonTransactional) + if err != nil { + if err == utils.ErrNotFound { + continue + } + return nil, err + } + if rPrf.ActivationInterval != nil && ev.Time != nil && + !rPrf.ActivationInterval.IsActiveAtTime(*ev.Time) { // not active + continue + } + if pass, err := rpS.filterS.Pass(ev.Tenant, rPrf.FilterIDs, + evNm); err != nil { + return nil, err + } else if !pass { + continue + } + if singleResult { + if matchingRPrf[0] == nil || matchingRPrf[0].Weight < rPrf.Weight { + matchingRPrf[0] = rPrf + } + } else { + matchingRPrf = append(matchingRPrf, rPrf) + } + } + if singleResult { + if matchingRPrf[0] == nil { + return nil, utils.ErrNotFound + } + } else { + if len(matchingRPrf) == 0 { + return nil, utils.ErrNotFound + } + sort.Slice(matchingRPrf, func(i, j int) bool { return matchingRPrf[i].Weight > matchingRPrf[j].Weight }) + } + return +} +*/ + +// V1CostForEvent will be called to calculate the cost for an event +func (rS *RateS) V1CostForEvent(cgrEv *utils.CGREventWithOpts, cC *utils.ChargedCost) (err error) { return } diff --git a/utils/consts.go b/utils/consts.go index 56c456677..5282640fe 100755 --- a/utils/consts.go +++ b/utils/consts.go @@ -105,6 +105,11 @@ var ( CacheRateProfilesFilterIndexes: RateProfilesFilterIndexPrfx, CacheLoadIDs: LoadIDPrefix, CacheAccounts: ACCOUNT_PREFIX, + CacheLoadIDs: LoadIDPrefix, + CacheAccounts: ACCOUNT_PREFIX, + CacheRateProfiles: RateProfilePrfx, + CacheRateProfilesFilterIndexes: RateProfilesFilterIndexPrfx, + CacheRateFilterIndexes: RateFilterIndexPrfx, } CachePrefixToInstance map[string]string // will be built on init PrefixToIndexCache = map[string]string{ @@ -271,6 +276,7 @@ const ( VERSION_PREFIX = "ver_" StatQueueProfilePrefix = "sqp_" RouteProfilePrefix = "rpp_" + RateProfilePrfx = "rtp_" AttributeProfilePrefix = "alp_" ChargerProfilePrefix = "cpp_" DispatcherProfilePrefix = "dpp_" @@ -1637,11 +1643,12 @@ const ( CacheAttributeFilterIndexes = "*attribute_filter_indexes" CacheChargerFilterIndexes = "*charger_filter_indexes" CacheDispatcherFilterIndexes = "*dispatcher_filter_indexes" - CacheRateProfilesFilterIndexes = "*rate_profile_filter_indexes" - CacheRateFilterIndexes = "*rate_filter_indexes" CacheDiameterMessages = "*diameter_messages" CacheRPCResponses = "*rpc_responses" CacheClosedSessions = "*closed_sessions" + CacheRateProfilesFilterIndexes = "*rate_profile_filter_indexes" + CacheRateFilterIndexes = "*rate_filter_indexes" + CacheRateProfiles = "*rate_profiles" MetaPrecaching = "*precaching" MetaReady = "*ready" CacheLoadIDs = "*load_ids"