From 30e419429d32785f2164fa886395edf91da5f252 Mon Sep 17 00:00:00 2001 From: ionutboangiu Date: Thu, 27 Jan 2022 18:03:02 +0200 Subject: [PATCH] Update match functions for dispatcher profiles --- engine/dispatcherprfl.go | 31 ++++++++++++++++++++++++++++++- engine/resources.go | 4 +++- utils/librates.go | 8 ++++---- 3 files changed, 37 insertions(+), 6 deletions(-) diff --git a/engine/dispatcherprfl.go b/engine/dispatcherprfl.go index 543029de4..5e7600ce5 100644 --- a/engine/dispatcherprfl.go +++ b/engine/dispatcherprfl.go @@ -311,7 +311,20 @@ func (dP *DispatcherProfile) Merge(v2 interface{}) { dP.ID = vi.ID } dP.FilterIDs = append(dP.FilterIDs, vi.FilterIDs...) - dP.Hosts = append(dP.Hosts, vi.Hosts...) + var equal bool + for _, hostV2 := range vi.Hosts { + for _, host := range dP.Hosts { + if host.ID == hostV2.ID { + host.Merge(hostV2) + equal = true + break + } + } + if !equal { + dP.Hosts = append(dP.Hosts, hostV2) + } + } + // dP.Hosts = append(dP.Hosts, vi.Hosts...) if vi.Weight != 0 { dP.Weight = vi.Weight } @@ -323,6 +336,22 @@ func (dP *DispatcherProfile) Merge(v2 interface{}) { } } +func (dspHost *DispatcherHostProfile) Merge(v2 *DispatcherHostProfile) { + if v2.ID != utils.EmptyString { + dspHost.ID = v2.ID + } + if v2.Weight != 0 { + dspHost.Weight = v2.Weight + } + if v2.Blocker { + dspHost.Blocker = v2.Blocker + } + dspHost.FilterIDs = append(dspHost.FilterIDs, v2.FilterIDs...) + for k, v := range v2.Params { + dspHost.Params[k] = v + } +} + func (dH *DispatcherHost) Merge(v2 interface{}) { vi := v2.(*DispatcherHost) if len(vi.Tenant) != 0 { diff --git a/engine/resources.go b/engine/resources.go index e7c5eef46..ae0b0d7e5 100644 --- a/engine/resources.go +++ b/engine/resources.go @@ -1042,7 +1042,9 @@ func (rp *ResourceProfile) Set(path []string, val interface{}, _ bool, _ string) case utils.UsageTTL: rp.UsageTTL, err = utils.IfaceAsDuration(val) case utils.Limit: - rp.Limit, err = utils.IfaceAsFloat64(val) + if val != utils.EmptyString { + rp.Limit, err = utils.IfaceAsFloat64(val) + } case utils.AllocationMessage: rp.AllocationMessage = utils.IfaceAsString(val) case utils.Blocker: diff --git a/utils/librates.go b/utils/librates.go index b4a6364a2..52a4d4b4d 100644 --- a/utils/librates.go +++ b/utils/librates.go @@ -602,8 +602,8 @@ func (rp *RateProfile) Set(path []string, val interface{}, newBranch bool, _ str valA, err = IfaceAsStringSlice(val) rp.FilterIDs = append(rp.FilterIDs, valA...) case Weights: - if weights := IfaceAsString(val); weights != EmptyString { - rp.Weights, err = NewDynamicWeightsFromString(weights, InfieldSep, ANDSep) + if val != EmptyString { + rp.Weights, err = NewDynamicWeightsFromString(IfaceAsString(val), InfieldSep, ANDSep) } case MinCost: if val != EmptyString { @@ -639,8 +639,8 @@ func (rt *Rate) Set(path []string, val interface{}, newBranch bool) (err error) valA, err = IfaceAsStringSlice(val) rt.FilterIDs = append(rt.FilterIDs, valA...) case Weights: - if weights := IfaceAsString(val); weights != EmptyString { - rt.Weights, err = NewDynamicWeightsFromString(weights, InfieldSep, ANDSep) + if val != EmptyString { + rt.Weights, err = NewDynamicWeightsFromString(IfaceAsString(val), InfieldSep, ANDSep) } case ActivationTimes: rt.ActivationTimes = IfaceAsString(val)