mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-11 18:16:24 +05:00
Add weights, blockers, and filterIDs functionality to *httpPost action diktats
This commit is contained in:
committed by
Dan Christian Bogos
parent
9fa6844fae
commit
f85ceebf85
@@ -56,9 +56,6 @@ func (aL *actSetBalance) execute(ctx *context.Context, data utils.MapStorage, tr
|
||||
weights := make(map[string]float64) // stores sorting weights by Diktat ID
|
||||
diktats := make([]*utils.APDiktat, 0) // list of diktats which have *balancePath in opts, will be weight sorted later
|
||||
for _, diktat := range aL.cfg().Diktats {
|
||||
if _, has := diktat.Opts[utils.MetaBalancePath]; !has {
|
||||
continue
|
||||
}
|
||||
if pass, err := aL.fltrS.Pass(ctx, aL.tnt, diktat.FilterIDs, data); err != nil {
|
||||
return err
|
||||
} else if !pass {
|
||||
@@ -132,9 +129,6 @@ func (aL *actRemBalance) execute(ctx *context.Context, data utils.MapStorage, tr
|
||||
weights := make(map[string]float64) // stores sorting weights by Diktat ID
|
||||
diktats := make([]*utils.APDiktat, 0) // list of diktats which have *balancePath in opts, will be weight sorted later
|
||||
for _, diktat := range aL.cfg().Diktats {
|
||||
if _, has := diktat.Opts[utils.MetaBalancePath]; !has {
|
||||
continue
|
||||
}
|
||||
if pass, err := aL.fltrS.Pass(ctx, aL.tnt, diktat.FilterIDs, data); err != nil {
|
||||
return err
|
||||
} else if !pass {
|
||||
|
||||
@@ -97,9 +97,6 @@ func (aL *actDynamicThreshold) execute(ctx *context.Context, data utils.MapStora
|
||||
weights := make(map[string]float64) // stores sorting weights by Diktat ID
|
||||
diktats := make([]*utils.APDiktat, 0) // list of diktats which have *template in opts, will be weight sorted later
|
||||
for _, diktat := range aL.aCfg.Diktats {
|
||||
if _, has := diktat.Opts[utils.MetaTemplate]; !has {
|
||||
continue
|
||||
}
|
||||
if pass, err := aL.fltrS.Pass(ctx, aL.tnt, diktat.FilterIDs, data); err != nil {
|
||||
return err
|
||||
} else if !pass {
|
||||
@@ -269,9 +266,6 @@ func (aL *actDynamicStats) execute(ctx *context.Context, data utils.MapStorage,
|
||||
weights := make(map[string]float64) // stores sorting weights by Diktat ID
|
||||
diktats := make([]*utils.APDiktat, 0) // list of diktats which have *template in opts, will be weight sorted later
|
||||
for _, diktat := range aL.aCfg.Diktats {
|
||||
if _, has := diktat.Opts[utils.MetaTemplate]; !has {
|
||||
continue
|
||||
}
|
||||
if pass, err := aL.fltrS.Pass(ctx, aL.tnt, diktat.FilterIDs, data); err != nil {
|
||||
return err
|
||||
} else if !pass {
|
||||
@@ -483,9 +477,6 @@ func (aL *actDynamicAttribute) execute(ctx *context.Context, data utils.MapStora
|
||||
weights := make(map[string]float64) // stores sorting weights by Diktat ID
|
||||
diktats := make([]*utils.APDiktat, 0) // list of diktats which have *template in opts, will be weight sorted later
|
||||
for _, diktat := range aL.aCfg.Diktats {
|
||||
if _, has := diktat.Opts[utils.MetaTemplate]; !has {
|
||||
continue
|
||||
}
|
||||
if pass, err := aL.fltrS.Pass(ctx, aL.tnt, diktat.FilterIDs, data); err != nil {
|
||||
return err
|
||||
} else if !pass {
|
||||
@@ -662,9 +653,6 @@ func (aL *actDynamicResource) execute(ctx *context.Context, data utils.MapStorag
|
||||
weights := make(map[string]float64) // stores sorting weights by Diktat ID
|
||||
diktats := make([]*utils.APDiktat, 0) // list of diktats which have *template in opts, will be weight sorted later
|
||||
for _, diktat := range aL.aCfg.Diktats {
|
||||
if _, has := diktat.Opts[utils.MetaTemplate]; !has {
|
||||
continue
|
||||
}
|
||||
if pass, err := aL.fltrS.Pass(ctx, aL.tnt, diktat.FilterIDs, data); err != nil {
|
||||
return err
|
||||
} else if !pass {
|
||||
|
||||
@@ -19,8 +19,10 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
package actions
|
||||
|
||||
import (
|
||||
"cmp"
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
"slices"
|
||||
"strings"
|
||||
|
||||
"github.com/cgrates/birpc/context"
|
||||
@@ -32,12 +34,32 @@ import (
|
||||
|
||||
func newActHTTPPost(ctx *context.Context, tnt string, cgrEv *utils.CGREvent,
|
||||
fltrS *engine.FilterS, cfg *config.CGRConfig, aCfg *utils.APAction) (aL *actHTTPPost, err error) {
|
||||
weights := make(map[string]float64) // stores sorting weights by Diktat ID
|
||||
diktats := make([]*utils.APDiktat, 0) // list of diktats which have *balancePath in opts, will be weight sorted later
|
||||
data := cgrEv.AsDataProvider()
|
||||
for _, diktat := range aCfg.Diktats {
|
||||
if pass, err := fltrS.Pass(ctx, cfg.GeneralCfg().DefaultTenant, diktat.FilterIDs, data); err != nil {
|
||||
return nil, err
|
||||
} else if !pass {
|
||||
continue
|
||||
}
|
||||
weight, err := engine.WeightFromDynamics(ctx, diktat.Weights, fltrS, cfg.GeneralCfg().DefaultTenant, data)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
weights[diktat.ID] = weight
|
||||
diktats = append(diktats, diktat)
|
||||
}
|
||||
// Sort by weight (higher values first).
|
||||
slices.SortFunc(diktats, func(a, b *utils.APDiktat) int {
|
||||
return cmp.Compare(weights[b.ID], weights[a.ID])
|
||||
})
|
||||
aL = &actHTTPPost{
|
||||
config: cfg,
|
||||
aCfg: aCfg,
|
||||
pstrs: make([]*ees.HTTPjsonMapEE, len(aCfg.Diktats)),
|
||||
pstrs: make([]*ees.HTTPjsonMapEE, len(diktats)),
|
||||
}
|
||||
for i, actD := range aL.cfg().Diktats {
|
||||
for i, actD := range diktats {
|
||||
attempts, err := engine.GetIntOpts(ctx, tnt, cgrEv.AsDataProvider(), nil, fltrS, cfg.ActionSCfg().Opts.PosterAttempts,
|
||||
utils.MetaPosterAttempts)
|
||||
if err != nil {
|
||||
@@ -48,6 +70,11 @@ func newActHTTPPost(ctx *context.Context, tnt string, cgrEv *utils.CGREvent,
|
||||
cfg.EEsCfg().ExporterCfg(utils.MetaDefault).FailedPostsDir,
|
||||
attempts, nil)
|
||||
aL.pstrs[i], _ = ees.NewHTTPjsonMapEE(eeCfg, cfg, nil, nil)
|
||||
if blocker, err := engine.BlockerFromDynamics(ctx, actD.Blockers, aL.fltrS, aL.config.GeneralCfg().DefaultTenant, data); err != nil {
|
||||
return nil, err
|
||||
} else if blocker {
|
||||
break
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
@@ -55,6 +82,7 @@ func newActHTTPPost(ctx *context.Context, tnt string, cgrEv *utils.CGREvent,
|
||||
type actHTTPPost struct {
|
||||
config *config.CGRConfig
|
||||
aCfg *utils.APAction
|
||||
fltrS *engine.FilterS
|
||||
|
||||
pstrs []*ees.HTTPjsonMapEE
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user