mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-24 00:28:44 +05:00
Updated all the loaders types
This commit is contained in:
committed by
Dan Christian Bogos
parent
1f89ef6ee7
commit
fd5cf12eac
@@ -20,6 +20,7 @@ package engine
|
||||
|
||||
import (
|
||||
"sort"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/cgrates/cgrates/config"
|
||||
@@ -85,3 +86,116 @@ type ActionProfileWithAPIOpts struct {
|
||||
*ActionProfile
|
||||
APIOpts map[string]interface{}
|
||||
}
|
||||
|
||||
func (aP *ActionProfile) Set(path []string, val interface{}, newBranch bool, _ string) (err error) {
|
||||
switch len(path) {
|
||||
case 0:
|
||||
return utils.ErrWrongPath
|
||||
case 1:
|
||||
switch path[0] {
|
||||
default:
|
||||
if strings.HasPrefix(path[0], utils.Targets) &&
|
||||
path[0][7] == '[' && path[0][len(path[0])-1] == ']' {
|
||||
var valA []string
|
||||
valA, err = utils.IfaceAsStringSlice(val)
|
||||
aP.Targets[path[0][8:len(path[0])-1]] = utils.NewStringSet(valA)
|
||||
return
|
||||
}
|
||||
return utils.ErrWrongPath
|
||||
case utils.Tenant:
|
||||
aP.Tenant = utils.IfaceAsString(val)
|
||||
case utils.ID:
|
||||
aP.ID = utils.IfaceAsString(val)
|
||||
case utils.Schedule:
|
||||
aP.Schedule = utils.IfaceAsString(val)
|
||||
case utils.FilterIDs:
|
||||
aP.FilterIDs, err = utils.IfaceAsStringSlice(val)
|
||||
case utils.Weight:
|
||||
aP.Weight, err = utils.IfaceAsFloat64(val)
|
||||
}
|
||||
return
|
||||
case 2:
|
||||
if path[0] == utils.Targets {
|
||||
var valA []string
|
||||
valA, err = utils.IfaceAsStringSlice(val)
|
||||
aP.Targets[path[1]] = utils.NewStringSet(valA)
|
||||
return
|
||||
}
|
||||
default:
|
||||
}
|
||||
|
||||
var acID string
|
||||
if strings.HasPrefix(path[0], utils.Actions) &&
|
||||
path[0][5] == '[' && path[0][len(path[0])-1] == ']' {
|
||||
acID = path[0][6 : len(path[0])-1]
|
||||
} else if path[0] == utils.Actions {
|
||||
acID = path[1]
|
||||
path = path[1:]
|
||||
}
|
||||
if acID == utils.EmptyString {
|
||||
return utils.ErrWrongPath
|
||||
}
|
||||
|
||||
var ac *APAction
|
||||
for _, a := range aP.Actions {
|
||||
if a.ID == acID {
|
||||
ac = a
|
||||
break
|
||||
}
|
||||
}
|
||||
if ac == nil {
|
||||
ac = &APAction{ID: acID, Opts: make(map[string]interface{})}
|
||||
aP.Actions = append(aP.Actions, ac)
|
||||
}
|
||||
|
||||
return ac.Set(path[1:], val, newBranch)
|
||||
}
|
||||
|
||||
func (aP *APAction) Set(path []string, val interface{}, newBranch bool) (err error) {
|
||||
switch len(path) {
|
||||
default:
|
||||
if path[0] == utils.Opts {
|
||||
return utils.MapStorage(aP.Opts).Set(path[1:], val)
|
||||
}
|
||||
return utils.ErrWrongPath
|
||||
case 0:
|
||||
return utils.ErrWrongPath
|
||||
case 1:
|
||||
switch path[0] {
|
||||
default:
|
||||
if strings.HasPrefix(path[0], utils.Opts) &&
|
||||
path[0][4] == '[' && path[0][len(path[0])-1] == ']' {
|
||||
aP.Opts[path[0][5:len(path[0])-1]] = val
|
||||
}
|
||||
return utils.ErrWrongPath
|
||||
case utils.ID:
|
||||
aP.ID = utils.IfaceAsString(val)
|
||||
case utils.Type:
|
||||
aP.Type = utils.IfaceAsString(val)
|
||||
case utils.FilterIDs:
|
||||
aP.FilterIDs, err = utils.IfaceAsStringSlice(val)
|
||||
case utils.Blocker:
|
||||
aP.Blocker, err = utils.IfaceAsBool(val)
|
||||
case utils.TTL:
|
||||
aP.TTL, err = utils.IfaceAsDuration(val)
|
||||
}
|
||||
case 2:
|
||||
switch path[0] {
|
||||
default:
|
||||
return utils.ErrWrongPath
|
||||
case utils.Opts:
|
||||
return utils.MapStorage(aP.Opts).Set(path[1:], val)
|
||||
case utils.Diktats:
|
||||
if len(aP.Diktats) == 0 || newBranch {
|
||||
aP.Diktats = append(aP.Diktats, new(APDiktat))
|
||||
}
|
||||
switch path[1] {
|
||||
case utils.Path:
|
||||
aP.Diktats[len(aP.Diktats)-1].Path = utils.IfaceAsString(val)
|
||||
case utils.Value:
|
||||
aP.Diktats[len(aP.Diktats)-1].Value = utils.IfaceAsString(val)
|
||||
}
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
@@ -21,6 +21,7 @@ package engine
|
||||
import (
|
||||
"math/rand"
|
||||
"sort"
|
||||
"strings"
|
||||
|
||||
"github.com/cgrates/birpc"
|
||||
"github.com/cgrates/birpc/context"
|
||||
@@ -187,3 +188,103 @@ func (dHPrflIDs DispatcherHostIDs) Clone() (cln DispatcherHostIDs) {
|
||||
copy(cln, dHPrflIDs)
|
||||
return
|
||||
}
|
||||
|
||||
func (dP *DispatcherProfile) Set(path []string, val interface{}, newBranch bool, _ string) (err error) {
|
||||
switch len(path) {
|
||||
default:
|
||||
return utils.ErrWrongPath
|
||||
case 1:
|
||||
switch path[0] {
|
||||
default:
|
||||
if strings.HasPrefix(path[0], utils.StrategyParams) &&
|
||||
path[0][14] == '[' && path[0][len(path[0])-1] == ']' {
|
||||
dP.StrategyParams[path[0][15:len(path[0])-1]] = val
|
||||
return
|
||||
}
|
||||
return utils.ErrWrongPath
|
||||
case utils.Tenant:
|
||||
dP.Tenant = utils.IfaceAsString(val)
|
||||
case utils.ID:
|
||||
dP.ID = utils.IfaceAsString(val)
|
||||
case utils.FilterIDs:
|
||||
dP.FilterIDs, err = utils.IfaceAsStringSlice(val)
|
||||
case utils.Strategy:
|
||||
dP.Strategy = utils.IfaceAsString(val)
|
||||
case utils.Weight:
|
||||
dP.Weight, err = utils.IfaceAsFloat64(val)
|
||||
}
|
||||
case 2:
|
||||
switch path[0] {
|
||||
default:
|
||||
return utils.ErrWrongPath
|
||||
case utils.StrategyParams:
|
||||
dP.StrategyParams[path[1]] = val
|
||||
case utils.Hosts:
|
||||
if len(dP.Hosts) == 0 || newBranch {
|
||||
dP.Hosts = append(dP.Hosts, &DispatcherHostProfile{Params: make(map[string]interface{})})
|
||||
}
|
||||
switch path[1] {
|
||||
case utils.ID:
|
||||
dP.Hosts[len(dP.Hosts)-1].ID = utils.IfaceAsString(val)
|
||||
case utils.FilterIDs:
|
||||
dP.Hosts[len(dP.Hosts)-1].FilterIDs, err = utils.IfaceAsStringSlice(val)
|
||||
case utils.Weights:
|
||||
dP.Hosts[len(dP.Hosts)-1].Weight, err = utils.IfaceAsFloat64(val)
|
||||
case utils.Blocker:
|
||||
dP.Hosts[len(dP.Hosts)-1].Blocker, err = utils.IfaceAsBool(val)
|
||||
default:
|
||||
if strings.HasPrefix(path[0], utils.Params) &&
|
||||
path[0][6] == '[' && path[0][len(path[0])-1] == ']' {
|
||||
dP.Hosts[len(dP.Hosts)-1].Params[path[0][7:len(path[0])-1]] = val
|
||||
return
|
||||
}
|
||||
return utils.ErrWrongPath
|
||||
}
|
||||
}
|
||||
case 3:
|
||||
if path[0] != utils.Hosts ||
|
||||
path[1] != utils.Params {
|
||||
return utils.ErrWrongPath
|
||||
}
|
||||
if len(dP.Hosts) == 0 || newBranch {
|
||||
dP.Hosts = append(dP.Hosts, new(DispatcherHostProfile))
|
||||
}
|
||||
dP.Hosts[len(dP.Hosts)-1].Params[path[2]] = val
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (dH *DispatcherHost) Set(path []string, val interface{}, newBranch bool, _ string) (err error) {
|
||||
if len(path) != 1 {
|
||||
return utils.ErrWrongPath
|
||||
}
|
||||
switch path[0] {
|
||||
default:
|
||||
return utils.ErrWrongPath
|
||||
case utils.Tenant:
|
||||
dH.Tenant = utils.IfaceAsString(val)
|
||||
case utils.ID:
|
||||
dH.ID = utils.IfaceAsString(val)
|
||||
case utils.Address:
|
||||
dH.Address = utils.IfaceAsString(val)
|
||||
case utils.Transport:
|
||||
dH.Transport = utils.IfaceAsString(val)
|
||||
case utils.ClientKey:
|
||||
dH.ClientKey = utils.IfaceAsString(val)
|
||||
case utils.ClientCertificate:
|
||||
dH.ClientCertificate = utils.IfaceAsString(val)
|
||||
case utils.CaCertificate:
|
||||
dH.CaCertificate = utils.IfaceAsString(val)
|
||||
case utils.ConnectAttempts:
|
||||
dH.ConnectAttempts, err = utils.IfaceAsTInt(val)
|
||||
case utils.Reconnects:
|
||||
dH.Reconnects, err = utils.IfaceAsTInt(val)
|
||||
case utils.ConnectTimeout:
|
||||
dH.ConnectTimeout, err = utils.IfaceAsDuration(val)
|
||||
case utils.ReplyTimeout:
|
||||
dH.ReplyTimeout, err = utils.IfaceAsDuration(val)
|
||||
case utils.TLS:
|
||||
dH.TLS, err = utils.IfaceAsBool(val)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
@@ -51,3 +51,26 @@ type ChargerProfiles []*ChargerProfile
|
||||
func (cps ChargerProfiles) Sort() {
|
||||
sort.Slice(cps, func(i, j int) bool { return cps[i].Weight > cps[j].Weight })
|
||||
}
|
||||
|
||||
func (cp *ChargerProfile) Set(path []string, val interface{}, newBranch bool, _ string) (err error) {
|
||||
if len(path) != 1 {
|
||||
return utils.ErrWrongPath
|
||||
}
|
||||
switch path[0] {
|
||||
default:
|
||||
return utils.ErrWrongPath
|
||||
case utils.Tenant:
|
||||
cp.Tenant = utils.IfaceAsString(val)
|
||||
case utils.ID:
|
||||
cp.ID = utils.IfaceAsString(val)
|
||||
case utils.FilterIDs:
|
||||
cp.FilterIDs, err = utils.IfaceAsStringSlice(val)
|
||||
case utils.RunID:
|
||||
cp.RunID = utils.IfaceAsString(val)
|
||||
case utils.AttributeIDs:
|
||||
cp.AttributeIDs, err = utils.IfaceAsStringSlice(val)
|
||||
case utils.Weight:
|
||||
cp.Weight, err = utils.IfaceAsFloat64(val)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
@@ -1023,7 +1023,7 @@ func (rS *ResourceS) V1GetResourceWithConfig(ctx *context.Context, arg *utils.Te
|
||||
}
|
||||
|
||||
func (rp *ResourceProfile) Set(path []string, val interface{}, _ bool, _ string) (err error) {
|
||||
if len(path) != 0 {
|
||||
if len(path) != 1 {
|
||||
return utils.ErrWrongPath
|
||||
}
|
||||
switch path[0] {
|
||||
|
||||
Reference in New Issue
Block a user