added blocker flag to models

This commit is contained in:
Radu Ioan Fericean
2016-01-12 22:57:17 +02:00
parent 13834eefbe
commit 7c6d2eb09a
8 changed files with 53 additions and 36 deletions

View File

@@ -42,7 +42,7 @@ type Action struct {
ActionType string
BalanceType string
ExtraParameters string
ExpirationString string
ExpirationString string // must stay as string because it can have relative values like 1month
Weight float64
Balance *Balance
}

View File

@@ -46,7 +46,8 @@ type ActionTrigger struct {
BalanceRatingSubject string // filter for balance
BalanceCategories utils.StringMap // filter for balance
BalanceSharedGroups utils.StringMap // filter for balance
BalanceDisabled bool // 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)
@@ -117,7 +118,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, disabled := 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
@@ -129,6 +130,7 @@ func (at *ActionTrigger) Match(a *Action) bool {
BalanceCategories string
BalanceSharedGroups string
BalanceTimingTags string
BalanceBlocker bool
BalanceDisabled bool
}{}
json.Unmarshal([]byte(a.ExtraParameters), &t)
@@ -141,9 +143,10 @@ func (at *ActionTrigger) Match(a *Action) bool {
sharedGroup = len(t.BalanceSharedGroups) == 0 || at.BalanceSharedGroups.Equal(utils.ParseStringMap(t.BalanceSharedGroups))
weight = t.BalanceWeight == 0 || at.BalanceWeight == t.BalanceWeight
ratingSubject = t.BalanceRatingSubject == "" || at.BalanceRatingSubject == t.BalanceRatingSubject
blocker = at.BalanceBlocker == t.BalanceBlocker
disabled = at.BalanceDisabled == t.BalanceDisabled
}
return id && direction && thresholdType && thresholdValue && destinationId && weight && ratingSubject && categories && sharedGroup && timings && disabled
return id && direction && thresholdType && thresholdValue && destinationId && weight && ratingSubject && categories && sharedGroup && timings && blocker && disabled
}
// makes a shallow copy of the receiver
@@ -163,6 +166,7 @@ func (at *ActionTrigger) CreateBalance() *Balance {
Categories: at.BalanceCategories,
SharedGroups: at.BalanceSharedGroups,
TimingIDs: at.BalanceTimingTags,
Blocker: at.BalanceBlocker,
Disabled: at.BalanceDisabled,
Weight: at.BalanceWeight,
}

View File

@@ -159,18 +159,18 @@ SG3,*any,*lowest,
*in,cgrates.org,call,*any,*any,*any,LCR_STANDARD,*lowest_cost,,2012-01-01T00:00:00Z,20
`
actions = `
MINI,*topup_reset,,,*monetary,*out,,,,,*unlimited,,10,10,false,10
MINI,*topup,,,*voice,*out,,NAT,test,,*unlimited,,100,10,false,10
SHARED,*topup,,,*monetary,*out,,,,SG1,*unlimited,,100,10,false,10
TOPUP10_AC,*topup_reset,,,*monetary,*out,,*any,,,*unlimited,,1,10,false,10
TOPUP10_AC1,*topup_reset,,,*voice,*out,,DST_UK_Mobile_BIG5,discounted_minutes,,*unlimited,,40,10,false,10
SE0,*topup_reset,,,*monetary,*out,,,,SG2,*unlimited,,0,10,false,10
SE10,*topup_reset,,,*monetary,*out,,,,SG2,*unlimited,,10,5,false,10
SE10,*topup,,,*monetary,*out,,,,,*unlimited,,10,10,false,10
EE0,*topup_reset,,,*monetary,*out,,,,SG3,*unlimited,,0,10,false,10
EE0,*allow_negative,,,*monetary,*out,,,,,*unlimited,,0,10,false,10
DEFEE,*cdrlog,"{""Category"":""^ddi"",""MediationRunId"":""^did_run""}",,,,,,,,,,,,false,10
NEG,*allow_negative,,,*monetary,*out,,,,,*unlimited,,0,10,false,10
MINI,*topup_reset,,,*monetary,*out,,,,,*unlimited,,10,10,false,false,10
MINI,*topup,,,*voice,*out,,NAT,test,,*unlimited,,100,10,false,false,10
SHARED,*topup,,,*monetary,*out,,,,SG1,*unlimited,,100,10,false,false,10
TOPUP10_AC,*topup_reset,,,*monetary,*out,,*any,,,*unlimited,,1,10,false,false,10
TOPUP10_AC1,*topup_reset,,,*voice,*out,,DST_UK_Mobile_BIG5,discounted_minutes,,*unlimited,,40,10,false,false,10
SE0,*topup_reset,,,*monetary,*out,,,,SG2,*unlimited,,0,10,false,false,10
SE10,*topup_reset,,,*monetary,*out,,,,SG2,*unlimited,,10,5,false,false,10
SE10,*topup,,,*monetary,*out,,,,,*unlimited,,10,10,false,false,10
EE0,*topup_reset,,,*monetary,*out,,,,SG3,*unlimited,,0,10,false,false,10
EE0,*allow_negative,,,*monetary,*out,,,,,*unlimited,,0,10,false,false,10
DEFEE,*cdrlog,"{""Category"":""^ddi"",""MediationRunId"":""^did_run""}",,,,,,,,,,,,false,false,10
NEG,*allow_negative,,,*monetary,*out,,,,,*unlimited,,0,10,false,false,10
`
actionPlans = `
MORE_MINUTES,MINI,ONE_TIME_RUN,10
@@ -184,16 +184,16 @@ POST_AT,NEG,*asap,10
`
actionTriggers = `
STANDARD_TRIGGER,st0,*min_event_counter,10,false,0,,*voice,*out,,GERMANY_O2,,,,,,,,SOME_1,10
STANDARD_TRIGGER,st1,*max_balance,200,false,0,,*voice,*out,,GERMANY,,,,,,,,SOME_2,10
STANDARD_TRIGGERS,,*min_balance,2,false,0,,*monetary,*out,,,,,,,,,,LOG_WARNING,10
STANDARD_TRIGGERS,,*max_balance,20,false,0,,*monetary,*out,,,,,,,,,,LOG_WARNING,10
STANDARD_TRIGGERS,,*max_event_counter,5,false,0,,*monetary,*out,,FS_USERS,,,,,,,,LOG_WARNING,10
CDRST1_WARN_ASR,,*min_asr,45,true,1h,,,,,,,,,,,,3,CDRST_WARN_HTTP,10
CDRST1_WARN_ACD,,*min_acd,10,true,1h,,,,,,,,,,,,5,CDRST_WARN_HTTP,10
CDRST1_WARN_ACC,,*max_acc,10,true,10m,,,,,,,,,,,,5,CDRST_WARN_HTTP,10
CDRST2_WARN_ASR,,*min_asr,30,true,0,,,,,,,,,,,,5,CDRST_WARN_HTTP,10
CDRST2_WARN_ACD,,*min_acd,3,true,0,,,,,,,,,,,,5,CDRST_WARN_HTTP,10
STANDARD_TRIGGER,st0,*min_event_counter,10,false,0,,*voice,*out,,GERMANY_O2,,,,,,,,,SOME_1,10
STANDARD_TRIGGER,st1,*max_balance,200,false,0,,*voice,*out,,GERMANY,,,,,,,,,SOME_2,10
STANDARD_TRIGGERS,,*min_balance,2,false,0,,*monetary,*out,,,,,,,,,,,LOG_WARNING,10
STANDARD_TRIGGERS,,*max_balance,20,false,0,,*monetary,*out,,,,,,,,,,,LOG_WARNING,10
STANDARD_TRIGGERS,,*max_event_counter,5,false,0,,*monetary,*out,,FS_USERS,,,,,,,,,LOG_WARNING,10
CDRST1_WARN_ASR,,*min_asr,45,true,1h,,,,,,,,,,,,,3,CDRST_WARN_HTTP,10
CDRST1_WARN_ACD,,*min_acd,10,true,1h,,,,,,,,,,,,,5,CDRST_WARN_HTTP,10
CDRST1_WARN_ACC,,*max_acc,10,true,10m,,,,,,,,,,,,,5,CDRST_WARN_HTTP,10
CDRST2_WARN_ASR,,*min_asr,30,true,0,,,,,,,,,,,,,5,CDRST_WARN_HTTP,10
CDRST2_WARN_ACD,,*min_acd,3,true,0,,,,,,,,,,,,,5,CDRST_WARN_HTTP,10
`
accountActions = `
vdf,minitsboy,MORE_MINUTES,STANDARD_TRIGGER,,

View File

@@ -179,6 +179,8 @@ func APItoModelAction(as *utils.TPActions) (result []TpAction) {
Categories: a.Categories,
SharedGroups: a.SharedGroups,
BalanceWeight: a.BalanceWeight,
BalanceBlocker: a.BalanceBlocker,
BalanceDisabled: a.BalanceDisabled,
ExtraParameters: a.ExtraParameters,
Weight: a.Weight,
})
@@ -231,6 +233,7 @@ func APItoModelActionTrigger(ats *utils.TPActionTriggers) (result []TpActionTrig
BalanceRatingSubject: at.BalanceRatingSubject,
BalanceCategories: at.BalanceCategories,
BalanceSharedGroups: at.BalanceSharedGroups,
BalanceBlocker: at.BalanceBlocker,
BalanceDisabled: at.BalanceDisabled,
MinQueuedItems: at.MinQueuedItems,
ActionsTag: at.ActionsId,

View File

@@ -396,6 +396,8 @@ func (tps TpActions) GetActions() (map[string][]*utils.TPAction, error) {
Categories: tpAc.Categories,
SharedGroups: tpAc.SharedGroups,
BalanceWeight: tpAc.BalanceWeight,
BalanceBlocker: tpAc.BalanceBlocker,
BalanceDisabled: tpAc.BalanceDisabled,
ExtraParameters: tpAc.ExtraParameters,
Weight: tpAc.Weight,
}
@@ -437,6 +439,7 @@ func (tps TpActionTriggers) GetActionTriggers() (map[string][]*utils.TPActionTri
BalanceRatingSubject: tpAt.BalanceRatingSubject,
BalanceCategories: tpAt.BalanceCategories,
BalanceSharedGroups: tpAt.BalanceSharedGroups,
BalanceBlocker: tpAt.BalanceBlocker,
BalanceDisabled: tpAt.BalanceDisabled,
Weight: tpAt.Weight,
ActionsId: tpAt.ActionsTag,

View File

@@ -265,8 +265,8 @@ func TestTPActionsAsExportSlice(t *testing.T) {
},
}
expectedSlc := [][]string{
[]string{"TEST_ACTIONS", "*topup_reset", "", "", "*monetary", utils.OUT, "call", "*any", "special1", "GROUP1", "*never", "", "5", "10", "false", "10"},
[]string{"TEST_ACTIONS", "*http_post", "http://localhost/&param1=value1", "", "", "", "", "", "", "", "", "", "0", "0", "false", "20"},
[]string{"TEST_ACTIONS", "*topup_reset", "", "", "*monetary", utils.OUT, "call", "*any", "special1", "GROUP1", "*never", "", "5", "10", "false", "false", "10"},
[]string{"TEST_ACTIONS", "*http_post", "http://localhost/&param1=value1", "", "", "", "", "", "", "", "", "", "0", "0", "false", "false", "20"},
}
ms := APItoModelAction(tpActs)
@@ -567,6 +567,7 @@ func TestTPActionPlanAsExportSlice(t *testing.T) {
BalanceRatingSubject: "special1",
BalanceCategories: "call",
BalanceSharedGroups: "SHARED_1",
BalanceBlocker: false,
BalanceDisabled: false,
MinQueuedItems: 0,
ActionsId: "LOG_WARNING",
@@ -588,6 +589,7 @@ func TestTPActionPlanAsExportSlice(t *testing.T) {
BalanceRatingSubject: "special1",
BalanceCategories: "call",
BalanceSharedGroups: "SHARED_1",
BalanceBlocker: false,
BalanceDisabled: false,
MinQueuedItems: 0,
ActionsId: "LOG_WARNING",
@@ -595,8 +597,8 @@ func TestTPActionPlanAsExportSlice(t *testing.T) {
},
}
expectedSlc := [][]string{
[]string{"STANDARD_TRIGGERS", "1", "*min_balance", "2", "false", "0", "b1", "*monetary", "*out", "call", "", "special1", "SHARED_1", "*never", "T1", "0", "false", "0", "LOG_WARNING", "10"},
[]string{"STANDARD_TRIGGERS", "2", "*max_event_counter", "5", "false", "0", "b2", "*monetary", "*out", "call", "FS_USERS", "special1", "SHARED_1", "*never", "T1", "0", "false", "0", "LOG_WARNING", "10"},
[]string{"STANDARD_TRIGGERS", "1", "*min_balance", "2", "false", "0", "b1", "*monetary", "*out", "call", "", "special1", "SHARED_1", "*never", "T1", "0", "false", "false", "0", "LOG_WARNING", "10"},
[]string{"STANDARD_TRIGGERS", "2", "*max_event_counter", "5", "false", "0", "b2", "*monetary", "*out", "call", "FS_USERS", "special1", "SHARED_1", "*never", "T1", "0", "false", "false", "0", "LOG_WARNING", "10"},
}
ms := APItoModelActionTrigger(at)
var slc [][]string

View File

@@ -167,8 +167,9 @@ type TpAction struct {
TimingTags string `index:"11" re:"[0-9A-Za-z_;]*|\*any"`
Units float64 `index:"12" re:"\d+\s*"`
BalanceWeight float64 `index:"13" re:"\d+\.?\d*\s*"`
BalanceDisabled bool `index:"14" re:""`
Weight float64 `index:"15" re:"\d+\.?\d*\s*"`
BalanceBlocker bool `index:"14" re:""`
BalanceDisabled bool `index:"15" re:""`
Weight float64 `index:"16" re:"\d+\.?\d*\s*"`
CreatedAt time.Time
}
@@ -201,10 +202,11 @@ type TpActionTrigger struct {
BalanceExpiryTime string `index:"13" re:"\*\w+\s*|\+\d+[smh]\s*|\d+\s*"`
BalanceTimingTags string `index:"14" re:"[0-9A-Za-z_;]*|\*any"`
BalanceWeight float64 `index:"15" re:"\d+\.?\d*"`
BalanceDisabled bool `index:"16" re:""`
MinQueuedItems int `index:"17" re:"\d+"`
ActionsTag string `index:"18" re:"\w+"`
Weight float64 `index:"19" re:"\d+\.?\d*"`
BalanceBlocker bool `index:"16" re:""`
BalanceDisabled bool `index:"17" re:""`
MinQueuedItems int `index:"18" re:"\d+"`
ActionsTag string `index:"19" re:"\w+"`
Weight float64 `index:"20" re:"\d+\.?\d*"`
CreatedAt time.Time
}

View File

@@ -286,6 +286,8 @@ type TPAction struct {
SharedGroups string // Reference to a shared group
BalanceWeight float64 // Balance weight
ExtraParameters string
BalanceBlocker bool
BalanceDisabled bool
Weight float64 // Action's weight
}
@@ -487,6 +489,7 @@ type TPActionTrigger struct {
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
MinQueuedItems int // Trigger actions only if this number is hit (stats only)
ActionsId string // Actions which will execute on threshold reached