Started adding merge function

This commit is contained in:
Trial97
2021-12-03 17:07:18 +02:00
committed by Dan Christian Bogos
parent bcfe27b878
commit c6ffe5ae91
6 changed files with 138 additions and 0 deletions

View File

@@ -736,3 +736,14 @@ func (fltr *Filter) Compress() {
}
fltr.Rules = newRules
}
func (fltr *Filter) Merge(v2 interface{}) {
vi := v2.(*Filter)
if len(vi.Tenant) != 0 {
fltr.Tenant = vi.Tenant
}
if len(vi.ID) != 0 {
fltr.ID = vi.ID
}
fltr.Rules = append(fltr.Rules, vi.Rules...)
}

View File

@@ -234,3 +234,21 @@ func (ap *AttributeProfile) Set(path []string, val interface{}, newBranch bool,
}
return
}
func (ap *AttributeProfile) Merge(v2 interface{}) {
vi := v2.(*AttributeProfile)
if len(vi.Tenant) != 0 {
ap.Tenant = vi.Tenant
}
if len(vi.ID) != 0 {
ap.ID = vi.ID
}
ap.FilterIDs = append(ap.FilterIDs, vi.FilterIDs...)
ap.Attributes = append(ap.Attributes, vi.Attributes...)
if vi.Blocker {
ap.Blocker = true
}
if vi.Weight != 0 {
ap.Weight = vi.Weight
}
}

View File

@@ -598,3 +598,35 @@ func (sqp *StatQueueProfile) Set(path []string, val interface{}, newBranch bool,
}
return
}
func (sqp *StatQueueProfile) Merge(v2 interface{}) {
vi := v2.(*StatQueueProfile)
if len(vi.Tenant) != 0 {
sqp.Tenant = vi.Tenant
}
if len(vi.ID) != 0 {
sqp.ID = vi.ID
}
sqp.FilterIDs = append(sqp.FilterIDs, vi.FilterIDs...)
sqp.ThresholdIDs = append(sqp.ThresholdIDs, vi.ThresholdIDs...)
sqp.Metrics = append(sqp.Metrics, vi.Metrics...)
if vi.QueueLength != 0 {
sqp.QueueLength = vi.QueueLength
}
if vi.TTL != 0 {
sqp.TTL = vi.TTL
}
if vi.MinItems != 0 {
sqp.MinItems = vi.MinItems
}
if vi.Blocker {
sqp.Blocker = vi.Blocker
}
if vi.Stored {
sqp.Stored = vi.Stored
}
if vi.Weight != 0 {
sqp.Weight = vi.Weight
}
}

View File

@@ -1056,3 +1056,33 @@ func (rp *ResourceProfile) Set(path []string, val interface{}, _ bool, _ string)
}
return
}
func (rp *ResourceProfile) Merge(v2 interface{}) {
vi := v2.(*ResourceProfile)
if len(vi.Tenant) != 0 {
rp.Tenant = vi.Tenant
}
if len(vi.ID) != 0 {
rp.ID = vi.ID
}
rp.FilterIDs = append(rp.FilterIDs, vi.FilterIDs...)
rp.ThresholdIDs = append(rp.ThresholdIDs, vi.ThresholdIDs...)
if len(vi.AllocationMessage) != 0 {
rp.AllocationMessage = vi.AllocationMessage
}
if vi.UsageTTL != 0 {
rp.UsageTTL = vi.UsageTTL
}
if vi.Limit != 0 {
rp.Limit = vi.Limit
}
if vi.Blocker {
rp.Blocker = vi.Blocker
}
if vi.Stored {
rp.Stored = vi.Stored
}
if vi.Weight != 0 {
rp.Weight = vi.Weight
}
}

View File

@@ -526,3 +526,20 @@ func (rp *RouteProfile) Set(path []string, val interface{}, newBranch bool, _ st
}
return
}
func (rp *RouteProfile) Merge(v2 interface{}) {
vi := v2.(*RouteProfile)
if len(vi.Tenant) != 0 {
rp.Tenant = vi.Tenant
}
if len(vi.ID) != 0 {
rp.ID = vi.ID
}
rp.FilterIDs = append(rp.FilterIDs, vi.FilterIDs...)
rp.SortingParameters = append(rp.SortingParameters, vi.SortingParameters...)
rp.Routes = append(rp.Routes, vi.Routes...)
rp.Weights = append(rp.Weights, vi.Weights...)
if len(vi.Sorting) != 0 {
rp.Sorting = vi.Sorting
}
}

View File

@@ -625,3 +625,33 @@ func (tp *ThresholdProfile) Set(path []string, val interface{}, _ bool, _ string
}
return
}
func (tp *ThresholdProfile) Merge(v2 interface{}) {
vi := v2.(*ThresholdProfile)
if len(vi.Tenant) != 0 {
tp.Tenant = vi.Tenant
}
if len(vi.ID) != 0 {
tp.ID = vi.ID
}
tp.FilterIDs = append(tp.FilterIDs, vi.FilterIDs...)
tp.ActionProfileIDs = append(tp.ActionProfileIDs, vi.ActionProfileIDs...)
if vi.Blocker {
tp.Blocker = vi.Blocker
}
if vi.Async {
tp.Async = vi.Async
}
if vi.Weight != 0 {
tp.Weight = vi.Weight
}
if vi.MaxHits != 0 {
tp.MaxHits = vi.MaxHits
}
if vi.MinHits != 0 {
tp.MinHits = vi.MinHits
}
if vi.MinSleep != 0 {
tp.MinSleep = vi.MinSleep
}
}