mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-11 18:16:24 +05:00
started action balance pointer filtering
This commit is contained in:
@@ -93,7 +93,7 @@ func (ub *Account) setBalanceAction(a *Action) error {
|
||||
if a == nil {
|
||||
return errors.New("nil action")
|
||||
}
|
||||
bClone := a.Balance.Clone()
|
||||
bClone := a.Balance.CreateBalance()
|
||||
if bClone == nil {
|
||||
return errors.New("nil balance")
|
||||
}
|
||||
@@ -182,7 +182,7 @@ func (ub *Account) debitBalanceAction(a *Action, reset bool) error {
|
||||
if a == nil {
|
||||
return errors.New("nil action")
|
||||
}
|
||||
bClone := a.Balance.Clone()
|
||||
bClone := a.Balance.CreateBalance()
|
||||
if bClone == nil {
|
||||
return errors.New("nil balance")
|
||||
}
|
||||
@@ -261,6 +261,7 @@ func (ub *Account) debitBalanceAction(a *Action, reset bool) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
/*
|
||||
func (ub *Account) enableDisableBalanceAction(a *Action) error {
|
||||
if a == nil {
|
||||
return errors.New("nil action")
|
||||
@@ -286,7 +287,7 @@ func (ub *Account) enableDisableBalanceAction(a *Action) error {
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
*/
|
||||
func (ub *Account) getBalancesForPrefix(prefix, category, direction, tor string, sharedGroup string) BalanceChain {
|
||||
var balances BalanceChain
|
||||
balances = append(balances, ub.BalanceMap[tor]...)
|
||||
@@ -933,23 +934,24 @@ func (acc *Account) AsOldStructure() interface{} {
|
||||
}
|
||||
}
|
||||
for i, at := range acc.ActionTriggers {
|
||||
b := at.Balance.CreateBalance()
|
||||
result.ActionTriggers[i] = &ActionTrigger{
|
||||
Id: at.ID,
|
||||
ThresholdType: at.ThresholdType,
|
||||
ThresholdValue: at.ThresholdValue,
|
||||
Recurrent: at.Recurrent,
|
||||
MinSleep: at.MinSleep,
|
||||
BalanceId: at.BalanceId,
|
||||
BalanceType: at.BalanceType,
|
||||
BalanceDirection: at.BalanceDirections.String(),
|
||||
BalanceDestinationIds: at.BalanceDestinationIds.String(),
|
||||
BalanceWeight: at.BalanceWeight,
|
||||
BalanceExpirationDate: at.BalanceExpirationDate,
|
||||
BalanceTimingTags: at.BalanceTimingTags.String(),
|
||||
BalanceRatingSubject: at.BalanceRatingSubject,
|
||||
BalanceCategory: at.BalanceCategories.String(),
|
||||
BalanceSharedGroup: at.BalanceSharedGroups.String(),
|
||||
BalanceDisabled: at.BalanceDisabled,
|
||||
BalanceId: b.Id,
|
||||
BalanceDirection: b.Directions.String(),
|
||||
BalanceDestinationIds: b.DestinationIds.String(),
|
||||
BalanceWeight: b.Weight,
|
||||
BalanceExpirationDate: b.ExpirationDate,
|
||||
BalanceTimingTags: b.TimingIDs.String(),
|
||||
BalanceRatingSubject: b.RatingSubject,
|
||||
BalanceCategory: b.Categories.String(),
|
||||
BalanceSharedGroup: b.SharedGroups.String(),
|
||||
BalanceDisabled: b.Disabled,
|
||||
Weight: at.Weight,
|
||||
ActionsId: at.ActionsId,
|
||||
MinQueuedItems: at.MinQueuedItems,
|
||||
|
||||
129
engine/action.go
129
engine/action.go
@@ -45,28 +45,93 @@ type Action struct {
|
||||
Filter string
|
||||
ExpirationString string // must stay as string because it can have relative values like 1month
|
||||
Weight float64
|
||||
Balance *Balance
|
||||
Balance *BalancePointer
|
||||
}
|
||||
|
||||
type BalancePointer struct {
|
||||
Uuid *string
|
||||
Id *string
|
||||
Value *float64
|
||||
Directions *utils.StringMap
|
||||
ExpirationDate *time.Time
|
||||
Weight *float64
|
||||
DestinationIds *utils.StringMap
|
||||
RatingSubject *string
|
||||
Categories *utils.StringMap
|
||||
SharedGroups *utils.StringMap
|
||||
TimingIDs *utils.StringMap
|
||||
Timings []*RITiming
|
||||
Disabled *bool
|
||||
Factor *ValueFactor
|
||||
Blocker *bool
|
||||
}
|
||||
|
||||
func (bp *BalancePointer) CreateBalance() *Balance {
|
||||
b := &Balance{}
|
||||
if bp.Uuid != nil {
|
||||
b.Uuid = *bp.Uuid
|
||||
}
|
||||
if bp.Id != nil {
|
||||
b.Id = *bp.Id
|
||||
}
|
||||
if bp.Value != nil {
|
||||
b.Value = *bp.Value
|
||||
}
|
||||
if bp.Directions != nil {
|
||||
b.Directions = *bp.Directions
|
||||
}
|
||||
if bp.ExpirationDate != nil {
|
||||
b.ExpirationDate = *bp.ExpirationDate
|
||||
}
|
||||
if bp.Weight != nil {
|
||||
b.Weight = *bp.Weight
|
||||
}
|
||||
if bp.DestinationIds != nil {
|
||||
b.DestinationIds = *bp.DestinationIds
|
||||
}
|
||||
if bp.RatingSubject != nil {
|
||||
b.RatingSubject = *bp.RatingSubject
|
||||
}
|
||||
if bp.Categories != nil {
|
||||
b.Categories = *bp.Categories
|
||||
}
|
||||
if bp.SharedGroups != nil {
|
||||
b.SharedGroups = *bp.SharedGroups
|
||||
}
|
||||
if bp.TimingIDs != nil {
|
||||
b.TimingIDs = *bp.TimingIDs
|
||||
}
|
||||
if bp.Disabled != nil {
|
||||
b.Disabled = *bp.Disabled
|
||||
}
|
||||
if bp.Factor != nil {
|
||||
b.Factor = *bp.Factor
|
||||
}
|
||||
if bp.Blocker != nil {
|
||||
b.Blocker = *bp.Blocker
|
||||
}
|
||||
return b.Clone()
|
||||
}
|
||||
|
||||
const (
|
||||
LOG = "*log"
|
||||
RESET_TRIGGERS = "*reset_triggers"
|
||||
SET_RECURRENT = "*set_recurrent"
|
||||
UNSET_RECURRENT = "*unset_recurrent"
|
||||
ALLOW_NEGATIVE = "*allow_negative"
|
||||
DENY_NEGATIVE = "*deny_negative"
|
||||
RESET_ACCOUNT = "*reset_account"
|
||||
REMOVE_ACCOUNT = "*remove_account"
|
||||
SET_BALANCE = "*set_balance" // not ready for production until switching to pointers
|
||||
REMOVE_BALANCE = "*remove_balance"
|
||||
TOPUP_RESET = "*topup_reset"
|
||||
TOPUP = "*topup"
|
||||
DEBIT_RESET = "*debit_reset"
|
||||
DEBIT = "*debit"
|
||||
RESET_COUNTERS = "*reset_counters"
|
||||
ENABLE_ACCOUNT = "*enable_account"
|
||||
DISABLE_ACCOUNT = "*disable_account"
|
||||
ENABLE_DISABLE_BALANCE = "*enable_disable_balance"
|
||||
LOG = "*log"
|
||||
RESET_TRIGGERS = "*reset_triggers"
|
||||
SET_RECURRENT = "*set_recurrent"
|
||||
UNSET_RECURRENT = "*unset_recurrent"
|
||||
ALLOW_NEGATIVE = "*allow_negative"
|
||||
DENY_NEGATIVE = "*deny_negative"
|
||||
RESET_ACCOUNT = "*reset_account"
|
||||
REMOVE_ACCOUNT = "*remove_account"
|
||||
SET_BALANCE = "*set_balance" // not ready for production until switching to pointers
|
||||
REMOVE_BALANCE = "*remove_balance"
|
||||
TOPUP_RESET = "*topup_reset"
|
||||
TOPUP = "*topup"
|
||||
DEBIT_RESET = "*debit_reset"
|
||||
DEBIT = "*debit"
|
||||
RESET_COUNTERS = "*reset_counters"
|
||||
ENABLE_ACCOUNT = "*enable_account"
|
||||
DISABLE_ACCOUNT = "*disable_account"
|
||||
//ENABLE_DISABLE_BALANCE = "*enable_disable_balance"
|
||||
CALL_URL = "*call_url"
|
||||
CALL_URL_ASYNC = "*call_url_async"
|
||||
MAIL_ASYNC = "*mail_async"
|
||||
@@ -84,7 +149,7 @@ func (a *Action) Clone() *Action {
|
||||
ExtraParameters: a.ExtraParameters,
|
||||
ExpirationString: a.ExpirationString,
|
||||
Weight: a.Weight,
|
||||
Balance: a.Balance.Clone(),
|
||||
Balance: a.Balance,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -122,8 +187,8 @@ func getActionFunc(typ string) (actionTypeFunc, bool) {
|
||||
return enableUserAction, true
|
||||
case DISABLE_ACCOUNT:
|
||||
return disableUserAction, true
|
||||
case ENABLE_DISABLE_BALANCE:
|
||||
return enableDisableBalanceAction, true
|
||||
//case ENABLE_DISABLE_BALANCE:
|
||||
// return enableDisableBalanceAction, true
|
||||
case CALL_URL:
|
||||
return callUrl, true
|
||||
case CALL_URL_ASYNC:
|
||||
@@ -167,6 +232,7 @@ func parseTemplateValue(rsrFlds utils.RSRFields, acnt *Account, action *Action)
|
||||
dta = new(utils.TenantAccount) // Init with empty values
|
||||
}
|
||||
var parsedValue string // Template values
|
||||
b := action.Balance.CreateBalance()
|
||||
for _, rsrFld := range rsrFlds {
|
||||
switch rsrFld.Id {
|
||||
case "AccountID":
|
||||
@@ -184,17 +250,17 @@ func parseTemplateValue(rsrFlds utils.RSRFields, acnt *Account, action *Action)
|
||||
case "BalanceType":
|
||||
parsedValue += rsrFld.ParseValue(action.BalanceType)
|
||||
case "BalanceUUID":
|
||||
parsedValue += rsrFld.ParseValue(action.Balance.Uuid)
|
||||
parsedValue += rsrFld.ParseValue(b.Uuid)
|
||||
case "BalanceID":
|
||||
parsedValue += rsrFld.ParseValue(action.Balance.Id)
|
||||
parsedValue += rsrFld.ParseValue(b.Id)
|
||||
case "BalanceValue":
|
||||
parsedValue += rsrFld.ParseValue(strconv.FormatFloat(action.Balance.GetValue(), 'f', -1, 64))
|
||||
parsedValue += rsrFld.ParseValue(strconv.FormatFloat(b.GetValue(), 'f', -1, 64))
|
||||
case "DestinationIDs":
|
||||
parsedValue += rsrFld.ParseValue(action.Balance.DestinationIds.String())
|
||||
parsedValue += rsrFld.ParseValue(b.DestinationIds.String())
|
||||
case "ExtraParameters":
|
||||
parsedValue += rsrFld.ParseValue(action.ExtraParameters)
|
||||
case "RatingSubject":
|
||||
parsedValue += rsrFld.ParseValue(action.Balance.RatingSubject)
|
||||
parsedValue += rsrFld.ParseValue(b.RatingSubject)
|
||||
case utils.CATEGORY:
|
||||
parsedValue += rsrFld.ParseValue(action.Balance.Categories.String())
|
||||
case "SharedGroups":
|
||||
@@ -370,8 +436,9 @@ func resetCountersAction(ub *Account, sq *StatsQueueTriggered, a *Action, acs Ac
|
||||
}
|
||||
|
||||
func genericMakeNegative(a *Action) {
|
||||
if a.Balance != nil && a.Balance.GetValue() >= 0 { // only apply if not allready negative
|
||||
a.Balance.SetValue(-a.Balance.GetValue())
|
||||
b := a.Balance.CreateBalance()
|
||||
if a.Balance != nil && b.GetValue() >= 0 { // only apply if not allready negative
|
||||
b.SetValue(-b.GetValue())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -401,13 +468,13 @@ func disableUserAction(ub *Account, sq *StatsQueueTriggered, a *Action, acs Acti
|
||||
return
|
||||
}
|
||||
|
||||
func enableDisableBalanceAction(ub *Account, sq *StatsQueueTriggered, a *Action, acs Actions) (err error) {
|
||||
/*func enableDisableBalanceAction(ub *Account, sq *StatsQueueTriggered, a *Action, acs Actions) (err error) {
|
||||
if ub == nil {
|
||||
return errors.New("nil account")
|
||||
}
|
||||
ub.enableDisableBalanceAction(a)
|
||||
return
|
||||
}
|
||||
}*/
|
||||
|
||||
func genericReset(ub *Account) error {
|
||||
for k, _ := range ub.BalanceMap {
|
||||
|
||||
@@ -308,7 +308,8 @@ func (at *ActionTiming) Execute() (err error) {
|
||||
//return 0, fmt.Errorf("Account %s is disabled", accID)
|
||||
}
|
||||
if expDate, parseErr := utils.ParseDate(a.ExpirationString); (a.Balance == nil || a.Balance.ExpirationDate.IsZero()) && parseErr == nil && !expDate.IsZero() {
|
||||
a.Balance.ExpirationDate = expDate
|
||||
a.Balance.ExpirationDate = &time.Time{}
|
||||
*a.Balance.ExpirationDate = expDate
|
||||
}
|
||||
|
||||
actionFunction, exists := getActionFunc(a.ActionType)
|
||||
@@ -339,7 +340,8 @@ func (at *ActionTiming) Execute() (err error) {
|
||||
|
||||
if expDate, parseErr := utils.ParseDate(a.ExpirationString); (a.Balance == nil || a.Balance.ExpirationDate.IsZero()) &&
|
||||
parseErr == nil && !expDate.IsZero() {
|
||||
a.Balance.ExpirationDate = expDate
|
||||
a.Balance.ExpirationDate = &time.Time{}
|
||||
*a.Balance.ExpirationDate = expDate
|
||||
}
|
||||
|
||||
actionFunction, exists := getActionFunc(a.ActionType)
|
||||
|
||||
@@ -33,28 +33,18 @@ type ActionTrigger struct {
|
||||
UniqueID string // individual id
|
||||
ThresholdType string //*min_event_counter, *max_event_counter, *min_balance_counter, *max_balance_counter, *min_balance, *max_balance, *exp_balance
|
||||
// stats: *min_asr, *max_asr, *min_acd, *max_acd, *min_tcd, *max_tcd, *min_acc, *max_acc, *min_tcc, *max_tcc, *min_ddc, *max_ddc
|
||||
ThresholdValue float64
|
||||
Recurrent bool // reset excuted flag each run
|
||||
MinSleep time.Duration // Minimum duration between two executions in case of recurrent triggers
|
||||
ExpirationDate time.Time
|
||||
ActivationDate time.Time
|
||||
BalanceId string
|
||||
BalanceType string // *monetary/*voice etc
|
||||
BalanceDirections utils.StringMap // filter for balance
|
||||
BalanceDestinationIds utils.StringMap // filter for balance
|
||||
BalanceWeight float64 // filter for balance
|
||||
BalanceExpirationDate time.Time // filter for balance
|
||||
BalanceTimingTags utils.StringMap // filter for balance
|
||||
BalanceRatingSubject string // filter for balance
|
||||
BalanceCategories utils.StringMap // filter for balance
|
||||
BalanceSharedGroups utils.StringMap // filter for balance
|
||||
BalanceBlocker bool
|
||||
BalanceDisabled bool // filter for balance
|
||||
Weight float64
|
||||
ActionsId string
|
||||
MinQueuedItems int // Trigger actions only if this number is hit (stats only)
|
||||
Executed bool
|
||||
lastExecutionTime time.Time
|
||||
ThresholdValue float64
|
||||
Recurrent bool // reset excuted flag each run
|
||||
MinSleep time.Duration // Minimum duration between two executions in case of recurrent triggers
|
||||
ExpirationDate time.Time
|
||||
ActivationDate time.Time
|
||||
BalanceType string // *monetary/*voice etc
|
||||
Balance *BalancePointer
|
||||
Weight float64
|
||||
ActionsId string
|
||||
MinQueuedItems int // Trigger actions only if this number is hit (stats only)
|
||||
Executed bool
|
||||
lastExecutionTime time.Time
|
||||
}
|
||||
|
||||
func (at *ActionTrigger) Execute(ub *Account, sq *StatsQueueTriggered) (err error) {
|
||||
@@ -90,9 +80,12 @@ func (at *ActionTrigger) Execute(ub *Account, sq *StatsQueueTriggered) (err erro
|
||||
}
|
||||
|
||||
if a.Balance == nil {
|
||||
a.Balance = &Balance{}
|
||||
a.Balance = &BalancePointer{}
|
||||
}
|
||||
if a.ExpirationString != "" {
|
||||
a.Balance.ExpirationDate = &time.Time{}
|
||||
*a.Balance.ExpirationDate, _ = utils.ParseDate(a.ExpirationString)
|
||||
}
|
||||
a.Balance.ExpirationDate, _ = utils.ParseDate(a.ExpirationString)
|
||||
actionFunction, exists := getActionFunc(a.ActionType)
|
||||
if !exists {
|
||||
utils.Logger.Err(fmt.Sprintf("Function type %v not available, aborting execution!", a.ActionType))
|
||||
@@ -131,7 +124,7 @@ func (at *ActionTrigger) Match(a *Action) bool {
|
||||
return match
|
||||
}
|
||||
id := a.BalanceType == "" || at.BalanceType == a.BalanceType
|
||||
thresholdType, thresholdValue, direction, destinationId, weight, ratingSubject, categories, sharedGroup, timings, blocker, disabled := true, true, true, true, true, true, true, true, true, true, true
|
||||
thresholdType, thresholdValue, direction, destinationID, weight, ratingSubject, categories, sharedGroup, timings, blocker, disabled := true, true, true, true, true, true, true, true, true, true, true
|
||||
if a.ExtraParameters != "" {
|
||||
t := struct {
|
||||
ThresholdType string
|
||||
@@ -149,8 +142,8 @@ func (at *ActionTrigger) Match(a *Action) bool {
|
||||
json.Unmarshal([]byte(a.ExtraParameters), &t)
|
||||
thresholdType = t.ThresholdType == "" || at.ThresholdType == t.ThresholdType
|
||||
thresholdValue = t.ThresholdValue == 0 || at.ThresholdValue == t.ThresholdValue
|
||||
direction = len(t.BalanceDirections) == 0 || at.BalanceDirections.Equal(utils.ParseStringMap(t.BalanceDirections))
|
||||
destinationId = len(t.DestinationIds) == 0 || at.BalanceDestinationIds.Equal(utils.ParseStringMap(t.DestinationIds))
|
||||
direction = t.Balance.Directions == nil || at.Balance.Directions.Equal(utils.ParseStringMap(t.BalanceDirections))
|
||||
destinationID = len(t.DestinationIds) == 0 || at.BalanceDestinationIds.Equal(utils.ParseStringMap(t.DestinationIds))
|
||||
categories = len(t.BalanceCategories) == 0 || at.BalanceCategories.Equal(utils.ParseStringMap(t.BalanceCategories))
|
||||
timings = len(t.BalanceTimingTags) == 0 || at.BalanceTimingTags.Equal(utils.ParseStringMap(t.BalanceTimingTags))
|
||||
sharedGroup = len(t.BalanceSharedGroups) == 0 || at.BalanceSharedGroups.Equal(utils.ParseStringMap(t.BalanceSharedGroups))
|
||||
@@ -159,7 +152,7 @@ func (at *ActionTrigger) Match(a *Action) bool {
|
||||
blocker = at.BalanceBlocker == t.BalanceBlocker
|
||||
disabled = at.BalanceDisabled == t.BalanceDisabled
|
||||
}
|
||||
return id && direction && thresholdType && thresholdValue && destinationId && weight && ratingSubject && categories && sharedGroup && timings && blocker && disabled
|
||||
return id && direction && thresholdType && thresholdValue && destinationID && weight && ratingSubject && categories && sharedGroup && timings && blocker && disabled
|
||||
}
|
||||
|
||||
// makes a shallow copy of the receiver
|
||||
|
||||
@@ -72,32 +72,26 @@ func (b *Balance) Equal(o *Balance) bool {
|
||||
b.Blocker == o.Blocker
|
||||
}
|
||||
|
||||
func (b *Balance) MatchFilter(o *Balance, skipIds bool) bool {
|
||||
func (b *Balance) MatchFilter(o *BalancePointer, skipIds bool) bool {
|
||||
if o == nil {
|
||||
return true
|
||||
}
|
||||
if !skipIds && o.Uuid != "" {
|
||||
return b.Uuid == o.Uuid
|
||||
if !skipIds && o.Uuid != nil && *o.Uuid != "" {
|
||||
return b.Uuid == *o.Uuid
|
||||
}
|
||||
if !skipIds && o.Id != "" {
|
||||
return b.Id == o.Id
|
||||
if !skipIds && o.Id != nil && *o.Id != "" {
|
||||
return b.Id == *o.Id
|
||||
}
|
||||
if len(b.DestinationIds) == 0 {
|
||||
b.DestinationIds = utils.StringMap{utils.ANY: true}
|
||||
}
|
||||
if len(o.DestinationIds) == 0 {
|
||||
o.DestinationIds = utils.StringMap{utils.ANY: true}
|
||||
}
|
||||
return (o.ExpirationDate.IsZero() || b.ExpirationDate.Equal(o.ExpirationDate)) &&
|
||||
(o.Weight == 0 || b.Weight == o.Weight) &&
|
||||
(b.Blocker == o.Blocker) &&
|
||||
(b.Disabled == o.Disabled) &&
|
||||
(len(o.DestinationIds) == 0 || b.DestinationIds.Includes(o.DestinationIds)) &&
|
||||
(len(o.Directions) == 0 || b.Directions.Includes(o.Directions)) &&
|
||||
(len(o.Categories) == 0 || b.Categories.Includes(o.Categories)) &&
|
||||
(len(o.TimingIDs) == 0 || b.TimingIDs.Includes(o.TimingIDs)) &&
|
||||
(len(o.SharedGroups) == 0 || b.SharedGroups.Includes(o.SharedGroups)) &&
|
||||
(o.RatingSubject == "" || b.RatingSubject == o.RatingSubject)
|
||||
return (o.ExpirationDate == nil || b.ExpirationDate.Equal(*o.ExpirationDate)) &&
|
||||
(o.Weight == nil || b.Weight == *o.Weight) &&
|
||||
(o.Blocker != nil || b.Blocker == *o.Blocker) &&
|
||||
(o.Disabled == nil || b.Disabled == *o.Disabled) &&
|
||||
(o.DestinationIds == nil || b.DestinationIds.Includes(*o.DestinationIds)) &&
|
||||
(o.Directions == nil || b.Directions.Includes(*o.Directions)) &&
|
||||
(o.Categories == nil || b.Categories.Includes(*o.Categories)) &&
|
||||
(o.TimingIDs == nil || b.TimingIDs.Includes(*o.TimingIDs)) &&
|
||||
(o.SharedGroups == nil || b.SharedGroups.Includes(*o.SharedGroups)) &&
|
||||
(o.RatingSubject == nil || b.RatingSubject == *o.RatingSubject)
|
||||
}
|
||||
|
||||
func (b *Balance) MatchCCFilter(cc *CallCost) bool {
|
||||
|
||||
@@ -166,10 +166,10 @@ type TpAction struct {
|
||||
SharedGroups string `index:"10" re:"[0-9A-Za-z_;]*"`
|
||||
ExpiryTime string `index:"11" re:"\*\w+\s*|\+\d+[smh]\s*|\d+\s*"`
|
||||
TimingTags string `index:"12" re:"[0-9A-Za-z_;]*|\*any"`
|
||||
Units float64 `index:"13" re:"\d+\s*"`
|
||||
BalanceWeight float64 `index:"14" re:"\d+\.?\d*\s*"`
|
||||
BalanceBlocker bool `index:"15" re:""`
|
||||
BalanceDisabled bool `index:"16" re:""`
|
||||
Units string `index:"13" re:"\d+\s*"`
|
||||
BalanceWeight string `index:"14" re:"\d+\.?\d*\s*"`
|
||||
BalanceBlocker string `index:"15" re:""`
|
||||
BalanceDisabled string `index:"16" re:""`
|
||||
Weight float64 `index:"17" re:"\d+\.?\d*\s*"`
|
||||
CreatedAt time.Time
|
||||
}
|
||||
@@ -204,9 +204,9 @@ type TpActionTrigger struct {
|
||||
BalanceSharedGroups string `index:"14" re:"\w+|\*any"`
|
||||
BalanceExpiryTime string `index:"15" re:"\*\w+\s*|\+\d+[smh]\s*|\d+\s*"`
|
||||
BalanceTimingTags string `index:"16" re:"[0-9A-Za-z_;]*|\*any"`
|
||||
BalanceWeight float64 `index:"17" re:"\d+\.?\d*"`
|
||||
BalanceBlocker bool `index:"18" re:""`
|
||||
BalanceDisabled bool `index:"19" re:""`
|
||||
BalanceWeight string `index:"17" re:"\d+\.?\d*"`
|
||||
BalanceBlocker string `index:"18" re:""`
|
||||
BalanceDisabled string `index:"19" re:""`
|
||||
MinQueuedItems int `index:"20" re:"\d+"`
|
||||
ActionsTag string `index:"21" re:"\w+"`
|
||||
Weight float64 `index:"22" re:"\d+\.?\d*"`
|
||||
|
||||
@@ -521,20 +521,61 @@ func (tpr *TpReader) LoadActions() (err error) {
|
||||
ExtraParameters: tpact.ExtraParameters,
|
||||
ExpirationString: tpact.ExpiryTime,
|
||||
Filter: tpact.Filter,
|
||||
Balance: &Balance{
|
||||
Id: tpact.BalanceId,
|
||||
Value: tpact.Units,
|
||||
Weight: tpact.BalanceWeight,
|
||||
RatingSubject: tpact.RatingSubject,
|
||||
Categories: utils.ParseStringMap(tpact.Categories),
|
||||
Directions: utils.ParseStringMap(tpact.Directions),
|
||||
DestinationIds: utils.ParseStringMap(tpact.DestinationIds),
|
||||
SharedGroups: utils.ParseStringMap(tpact.SharedGroups),
|
||||
TimingIDs: utils.ParseStringMap(tpact.TimingTags),
|
||||
Blocker: tpact.BalanceBlocker,
|
||||
Disabled: tpact.BalanceDisabled,
|
||||
},
|
||||
Balance: &BalancePointer{},
|
||||
}
|
||||
if tpact.BalanceId != "" && tpact.BalanceId != utils.ANY {
|
||||
acts[idx].Balance.Id = utils.StringPointer(tpact.BalanceId)
|
||||
}
|
||||
|
||||
if tpact.Units != "" && tpact.Units != utils.ANY {
|
||||
u, err := strconv.ParseFloat(tpact.Units, 64)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
acts[idx].Balance.Value = utils.Float64Pointer(u)
|
||||
}
|
||||
|
||||
if tpact.BalanceWeight != "" && tpact.BalanceWeight != utils.ANY {
|
||||
u, err := strconv.ParseFloat(tpact.BalanceWeight, 64)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
acts[idx].Balance.Weight = utils.Float64Pointer(u)
|
||||
}
|
||||
if tpact.RatingSubject != "" && tpact.RatingSubject != utils.ANY {
|
||||
acts[idx].Balance.RatingSubject = utils.StringPointer(tpact.RatingSubject)
|
||||
}
|
||||
|
||||
if tpact.Categories != "" && tpact.Categories != utils.ANY {
|
||||
acts[idx].Balance.Categories = utils.StringMapPointer(utils.ParseStringMap(tpact.Categories))
|
||||
}
|
||||
if tpact.Directions != "" && tpact.Directions != utils.ANY {
|
||||
acts[idx].Balance.Directions = utils.StringMapPointer(utils.ParseStringMap(tpact.Directions))
|
||||
}
|
||||
if tpact.DestinationIds != "" && tpact.DestinationIds != utils.ANY {
|
||||
acts[idx].Balance.DestinationIds = utils.StringMapPointer(utils.ParseStringMap(tpact.DestinationIds))
|
||||
}
|
||||
if tpact.SharedGroups != "" && tpact.SharedGroups != utils.ANY {
|
||||
acts[idx].Balance.SharedGroups = utils.StringMapPointer(utils.ParseStringMap(tpact.SharedGroups))
|
||||
}
|
||||
if tpact.TimingTags != "" && tpact.TimingTags != utils.ANY {
|
||||
acts[idx].Balance.TimingIDs = utils.StringMapPointer(utils.ParseStringMap(tpact.TimingTags))
|
||||
}
|
||||
if tpact.BalanceBlocker != "" && tpact.BalanceBlocker != utils.ANY {
|
||||
u, err := strconv.ParseBool(tpact.BalanceBlocker)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
acts[idx].Balance.Blocker = utils.BoolPointer(u)
|
||||
}
|
||||
if tpact.BalanceDisabled != "" && tpact.BalanceDisabled != utils.ANY {
|
||||
u, err := strconv.ParseBool(tpact.BalanceDisabled)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
acts[idx].Balance.Disabled = utils.BoolPointer(u)
|
||||
}
|
||||
|
||||
// load action timings from tags
|
||||
if tpact.TimingTags != "" {
|
||||
timingIds := strings.Split(tpact.TimingTags, utils.INFIELD_SEP)
|
||||
|
||||
34
glide.lock
generated
34
glide.lock
generated
@@ -1,5 +1,5 @@
|
||||
hash: 855bc23b0e58452edf1d31f228430476a2602b79d225397d33b805b252cebb83
|
||||
updated: 2016-01-21T12:30:17.296295607+02:00
|
||||
updated: 2016-02-05T16:54:55.433704333+02:00
|
||||
imports:
|
||||
- name: github.com/cenkalti/hub
|
||||
version: 57d753b5f4856e77b3cf8ecce78c97215a7d324d
|
||||
@@ -25,6 +25,8 @@ imports:
|
||||
- diam/datatype
|
||||
- diam/dict
|
||||
- diam/sm
|
||||
- diam/sm/smparser
|
||||
- diam/sm/smpeer
|
||||
- name: github.com/go-sql-driver/mysql
|
||||
version: bb006fd699a123d3eb514561dbefc352e978949d
|
||||
- name: github.com/gorhill/cronexpr
|
||||
@@ -37,11 +39,15 @@ imports:
|
||||
version: f7ee69f31298ecbe5d2b349c711e2547a617d398
|
||||
- name: github.com/lib/pq
|
||||
version: 11fc39a580a008f1f39bb3d11d984fb34ed778d9
|
||||
subpackages:
|
||||
- hstore
|
||||
- oid
|
||||
- name: github.com/mediocregopher/radix.v2
|
||||
version: 91435107718b55ff544323a2b0f25fdd8475d283
|
||||
subpackages:
|
||||
- /pool
|
||||
- redis
|
||||
- pool
|
||||
- name: github.com/peterh/liner
|
||||
version: 3f1c20449d1836aa4cbe38731b96f95cdf89634d
|
||||
- name: github.com/ugorji/go
|
||||
@@ -50,18 +56,44 @@ imports:
|
||||
- /codec
|
||||
- name: golang.org/x/crypto
|
||||
version: 552e9d568fde9701ea1944fb01c8aadaceaa7353
|
||||
subpackages:
|
||||
- ssh/terminal
|
||||
- name: golang.org/x/net
|
||||
version: 961116aeebe66bfb58bb4d51818c70d256acbbb8
|
||||
subpackages:
|
||||
- /websocket
|
||||
- context
|
||||
- html/atom
|
||||
- http2/hpack
|
||||
- internal/iana
|
||||
- ipv4
|
||||
- ipv6
|
||||
- webdav/internal/xml
|
||||
- name: golang.org/x/text
|
||||
version: cf4986612c83df6c55578ba198316d1684a9a287
|
||||
subpackages:
|
||||
- encoding
|
||||
- encoding/charmap
|
||||
- encoding/htmlindex
|
||||
- transform
|
||||
- encoding/internal/identifier
|
||||
- encoding/internal
|
||||
- encoding/japanese
|
||||
- encoding/korean
|
||||
- encoding/simplifiedchinese
|
||||
- encoding/traditionalchinese
|
||||
- encoding/unicode
|
||||
- language
|
||||
- internal/utf8internal
|
||||
- runes
|
||||
- internal/tag
|
||||
- name: gopkg.in/fsnotify.v1
|
||||
version: 508915b7500b6e42a87132e4afeb4729cebc7cbb
|
||||
- name: gopkg.in/mgo.v2
|
||||
version: e30de8ac9ae3b30df7065f766c71f88bba7d4e49
|
||||
subpackages:
|
||||
- bson
|
||||
- internal/scram
|
||||
- name: gopkg.in/tomb.v2
|
||||
version: 14b3d72120e8d10ea6e6b7f87f7175734b1faab8
|
||||
devImports: []
|
||||
|
||||
@@ -273,22 +273,22 @@ type TPActions struct {
|
||||
}
|
||||
|
||||
type TPAction struct {
|
||||
Identifier string // Identifier mapped in the code
|
||||
BalanceId string // Balance identification string (account scope)
|
||||
BalanceType string // Type of balance the action will operate on
|
||||
Directions string // Balance direction
|
||||
Units float64 // Number of units to add/deduct
|
||||
ExpiryTime string // Time when the units will expire
|
||||
Filter string // The condition on balances that is checked before the action
|
||||
TimingTags string // Timing when balance is active
|
||||
DestinationIds string // Destination profile id
|
||||
RatingSubject string // Reference a rate subject defined in RatingProfiles
|
||||
Categories string // category filter for balances
|
||||
SharedGroups string // Reference to a shared group
|
||||
BalanceWeight float64 // Balance weight
|
||||
Identifier string // Identifier mapped in the code
|
||||
BalanceId string // Balance identification string (account scope)
|
||||
BalanceType string // Type of balance the action will operate on
|
||||
Directions string // Balance direction
|
||||
Units string // Number of units to add/deduct
|
||||
ExpiryTime string // Time when the units will expire
|
||||
Filter string // The condition on balances that is checked before the action
|
||||
TimingTags string // Timing when balance is active
|
||||
DestinationIds string // Destination profile id
|
||||
RatingSubject string // Reference a rate subject defined in RatingProfiles
|
||||
Categories string // category filter for balances
|
||||
SharedGroups string // Reference to a shared group
|
||||
BalanceWeight string // Balance weight
|
||||
ExtraParameters string
|
||||
BalanceBlocker bool
|
||||
BalanceDisabled bool
|
||||
BalanceBlocker string
|
||||
BalanceDisabled string
|
||||
Weight float64 // Action's weight
|
||||
}
|
||||
|
||||
@@ -486,14 +486,14 @@ type TPActionTrigger struct {
|
||||
BalanceType string // Type of balance this trigger monitors
|
||||
BalanceDirections string // Traffic direction
|
||||
BalanceDestinationIds string // filter for balance
|
||||
BalanceWeight float64 // filter for balance
|
||||
BalanceWeight string // filter for balance
|
||||
BalanceExpirationDate string // filter for balance
|
||||
BalanceTimingTags string // filter for balance
|
||||
BalanceRatingSubject string // filter for balance
|
||||
BalanceCategories string // filter for balance
|
||||
BalanceSharedGroups string // filter for balance
|
||||
BalanceBlocker bool // filter for balance
|
||||
BalanceDisabled bool // filter for balance
|
||||
BalanceBlocker string // filter for balance
|
||||
BalanceDisabled string // filter for balance
|
||||
MinQueuedItems int // Trigger actions only if this number is hit (stats only)
|
||||
ActionsId string // Actions which will execute on threshold reached
|
||||
Weight float64 // weight
|
||||
|
||||
@@ -89,6 +89,7 @@ const (
|
||||
ROUNDING_MIDDLE = "*middle"
|
||||
ROUNDING_DOWN = "*down"
|
||||
ANY = "*any"
|
||||
ZERO = "*zero"
|
||||
ASAP = "*asap"
|
||||
USERS = "*users"
|
||||
COMMENT_CHAR = '#'
|
||||
|
||||
@@ -337,6 +337,10 @@ func Fib() func() time.Duration {
|
||||
|
||||
// Utilities to provide pointers where we need to define ad-hoc
|
||||
func StringPointer(str string) *string {
|
||||
if str == ZERO {
|
||||
str = ""
|
||||
return &str
|
||||
}
|
||||
return &str
|
||||
}
|
||||
|
||||
|
||||
@@ -74,6 +74,9 @@ func NewStringMap(s ...string) StringMap {
|
||||
}
|
||||
|
||||
func ParseStringMap(s string) StringMap {
|
||||
if s == ZERO {
|
||||
return make(StringMap)
|
||||
}
|
||||
return StringMapFromSlice(strings.Split(s, INFIELD_SEP))
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user