From ed9ed328f344eee1bfbf70d73c4c284b5d53fda1 Mon Sep 17 00:00:00 2001 From: Radu Ioan Fericean Date: Tue, 10 Nov 2015 09:31:45 +0200 Subject: [PATCH] added exp_balance action trigger --- engine/account.go | 18 +++++++---------- engine/account_test.go | 34 ++++++++++++++++---------------- engine/action_trigger.go | 2 +- engine/actions_test.go | 36 +++++++++++++++++----------------- engine/loader_csv_test.go | 4 ++-- engine/units_counter_test.go | 38 ++++++++++++++++++------------------ utils/consts.go | 8 ++++++++ 7 files changed, 72 insertions(+), 68 deletions(-) diff --git a/engine/account.go b/engine/account.go index a83a99dcc..efa46cb4e 100644 --- a/engine/account.go +++ b/engine/account.go @@ -30,16 +30,6 @@ import ( "strings" ) -const ( - // action trigger threshold types - TRIGGER_MIN_EVENT_COUNTER = "*min_event_counter" - TRIGGER_MIN_BALANCE_COUNTER = "*min_balance_counter" - TRIGGER_MAX_EVENT_COUNTER = "*max_event_counter" - TRIGGER_MAX_BALANCE_COUNTER = "*max_balance_counter" - TRIGGER_MIN_BALANCE = "*min_balance" - TRIGGER_MAX_BALANCE = "*max_balance" -) - /* Structure containing information about user's credit (minutes, cents, sms...).' This can represent a user or a shared group. @@ -512,7 +502,7 @@ func (ub *Account) executeActionTriggers(a *Action) { } } } - } else { // BALANCE + } else if at.ThresholdType == utils.TRIGGER_MIN_BALANCE || at.ThresholdType == utils.TRIGGER_MAX_BALANCE { // BALANCE THRESHOLD for _, b := range ub.BalanceMap[at.BalanceType] { if !b.dirty { // do not check clean balances continue @@ -529,6 +519,12 @@ func (ub *Account) executeActionTriggers(a *Action) { } } } + } else if at.ThresholdType == utils.TRIGGER_EXP_BALANCE { + for _, b := range ub.BalanceMap[at.BalanceType] { + if b.MatchActionTrigger(at) && b.IsExpired() { + at.Execute(ub, nil) + } + } } } } diff --git a/engine/account_test.go b/engine/account_test.go index 1cd5046a5..1647497a7 100644 --- a/engine/account_test.go +++ b/engine/account_test.go @@ -890,7 +890,7 @@ func TestAccountExecuteTriggeredActions(t *testing.T) { Id: "TEST_UB", BalanceMap: map[string]BalanceChain{utils.MONETARY: BalanceChain{&Balance{Directions: utils.NewStringMap(utils.OUT), Value: 100}}, utils.VOICE: BalanceChain{&Balance{Value: 10, Weight: 20, DestinationIds: utils.StringMap{"NAT": true}, Directions: utils.StringMap{utils.OUT: true}}, &Balance{Weight: 10, DestinationIds: utils.StringMap{"RET": true}}}}, UnitCounters: UnitCounters{&UnitCounter{BalanceType: utils.MONETARY, Balances: BalanceChain{&Balance{Value: 1, Directions: utils.StringMap{utils.OUT: true}}}}}, - ActionTriggers: ActionTriggers{&ActionTrigger{BalanceType: utils.MONETARY, BalanceDirections: utils.StringMap{utils.OUT: true}, ThresholdValue: 2, ThresholdType: TRIGGER_MAX_EVENT_COUNTER, ActionsId: "TEST_ACTIONS"}}, + ActionTriggers: ActionTriggers{&ActionTrigger{BalanceType: utils.MONETARY, BalanceDirections: utils.StringMap{utils.OUT: true}, ThresholdValue: 2, ThresholdType: utils.TRIGGER_MAX_EVENT_COUNTER, ActionsId: "TEST_ACTIONS"}}, } ub.countUnits(1, utils.MONETARY, &CallCost{Direction: utils.OUT}, nil) if ub.BalanceMap[utils.MONETARY][0].GetValue() != 110 || ub.BalanceMap[utils.VOICE][0].GetValue() != 20 { @@ -914,7 +914,7 @@ func TestAccountExecuteTriggeredActionsBalance(t *testing.T) { Id: "TEST_UB", BalanceMap: map[string]BalanceChain{utils.MONETARY: BalanceChain{&Balance{Directions: utils.NewStringMap(utils.OUT), Value: 100}}, utils.VOICE: BalanceChain{&Balance{Directions: utils.NewStringMap(utils.OUT), Value: 10, Weight: 20, DestinationIds: utils.StringMap{"NAT": true}}, &Balance{Directions: utils.NewStringMap(utils.OUT), Weight: 10, DestinationIds: utils.StringMap{"RET": true}}}}, UnitCounters: UnitCounters{&UnitCounter{BalanceType: utils.MONETARY, Balances: BalanceChain{&Balance{Directions: utils.NewStringMap(utils.OUT), Value: 1}}}}, - ActionTriggers: ActionTriggers{&ActionTrigger{BalanceType: utils.MONETARY, BalanceDirections: utils.NewStringMap(utils.OUT), ThresholdValue: 100, ThresholdType: TRIGGER_MIN_EVENT_COUNTER, ActionsId: "TEST_ACTIONS"}}, + ActionTriggers: ActionTriggers{&ActionTrigger{BalanceType: utils.MONETARY, BalanceDirections: utils.NewStringMap(utils.OUT), ThresholdValue: 100, ThresholdType: utils.TRIGGER_MIN_EVENT_COUNTER, ActionsId: "TEST_ACTIONS"}}, } ub.countUnits(1, utils.MONETARY, nil, nil) if ub.BalanceMap[utils.MONETARY][0].GetValue() != 110 || ub.BalanceMap[utils.VOICE][0].GetValue() != 20 { @@ -927,7 +927,7 @@ func TestAccountExecuteTriggeredActionsOrder(t *testing.T) { Id: "TEST_UB_OREDER", BalanceMap: map[string]BalanceChain{utils.MONETARY: BalanceChain{&Balance{Directions: utils.NewStringMap(utils.OUT), Value: 100}}}, UnitCounters: UnitCounters{&UnitCounter{BalanceType: utils.MONETARY, Balances: BalanceChain{&Balance{Value: 1, Directions: utils.NewStringMap(utils.OUT)}}}}, - ActionTriggers: ActionTriggers{&ActionTrigger{BalanceType: utils.MONETARY, ThresholdValue: 2, ThresholdType: TRIGGER_MAX_EVENT_COUNTER, ActionsId: "TEST_ACTIONS_ORDER"}}, + ActionTriggers: ActionTriggers{&ActionTrigger{BalanceType: utils.MONETARY, ThresholdValue: 2, ThresholdType: utils.TRIGGER_MAX_EVENT_COUNTER, ActionsId: "TEST_ACTIONS_ORDER"}}, } ub.countUnits(1, utils.MONETARY, &CallCost{Direction: utils.OUT}, nil) @@ -942,8 +942,8 @@ func TestAccountExecuteTriggeredDayWeek(t *testing.T) { Id: "TEST_UB", BalanceMap: map[string]BalanceChain{utils.MONETARY: BalanceChain{&Balance{Directions: utils.NewStringMap(utils.OUT), Value: 100}}, utils.VOICE: BalanceChain{&Balance{Value: 10, Weight: 20, DestinationIds: utils.StringMap{"NAT": true}, Directions: utils.StringMap{utils.OUT: true}}, &Balance{Weight: 10, DestinationIds: utils.StringMap{"RET": true}}}}, ActionTriggers: ActionTriggers{ - &ActionTrigger{Id: "day_trigger", BalanceType: utils.MONETARY, BalanceDirections: utils.StringMap{utils.OUT: true}, ThresholdValue: 10, ThresholdType: TRIGGER_MAX_EVENT_COUNTER, ActionsId: "TEST_ACTIONS"}, - &ActionTrigger{Id: "week_trigger", BalanceType: utils.MONETARY, BalanceDirections: utils.StringMap{utils.OUT: true}, ThresholdValue: 100, ThresholdType: TRIGGER_MAX_EVENT_COUNTER, ActionsId: "TEST_ACTIONS"}, + &ActionTrigger{Id: "day_trigger", BalanceType: utils.MONETARY, BalanceDirections: utils.StringMap{utils.OUT: true}, ThresholdValue: 10, ThresholdType: utils.TRIGGER_MAX_EVENT_COUNTER, ActionsId: "TEST_ACTIONS"}, + &ActionTrigger{Id: "week_trigger", BalanceType: utils.MONETARY, BalanceDirections: utils.StringMap{utils.OUT: true}, ThresholdValue: 100, ThresholdType: utils.TRIGGER_MAX_EVENT_COUNTER, ActionsId: "TEST_ACTIONS"}, }, } ub.InitCounters() @@ -1472,42 +1472,42 @@ func TestAccountInitCounters(t *testing.T) { ActionTriggers: ActionTriggers{ &ActionTrigger{ Id: "TestTR1", - ThresholdType: TRIGGER_MAX_EVENT_COUNTER, + ThresholdType: utils.TRIGGER_MAX_EVENT_COUNTER, BalanceType: utils.MONETARY, BalanceDirections: utils.NewStringMap(utils.OUT, utils.IN), BalanceWeight: 10, }, &ActionTrigger{ Id: "TestTR11", - ThresholdType: TRIGGER_MAX_EVENT_COUNTER, + ThresholdType: utils.TRIGGER_MAX_EVENT_COUNTER, BalanceType: utils.MONETARY, BalanceDirections: utils.NewStringMap(utils.OUT, utils.IN), BalanceWeight: 10, }, &ActionTrigger{ Id: "TestTR2", - ThresholdType: TRIGGER_MAX_EVENT_COUNTER, + ThresholdType: utils.TRIGGER_MAX_EVENT_COUNTER, BalanceType: utils.VOICE, BalanceDirections: utils.NewStringMap(utils.OUT, utils.IN), BalanceWeight: 10, }, &ActionTrigger{ Id: "TestTR3", - ThresholdType: TRIGGER_MAX_BALANCE_COUNTER, + ThresholdType: utils.TRIGGER_MAX_BALANCE_COUNTER, BalanceType: utils.VOICE, BalanceDirections: utils.NewStringMap(utils.OUT, utils.IN), BalanceWeight: 10, }, &ActionTrigger{ Id: "TestTR4", - ThresholdType: TRIGGER_MAX_BALANCE_COUNTER, + ThresholdType: utils.TRIGGER_MAX_BALANCE_COUNTER, BalanceType: utils.SMS, BalanceDirections: utils.NewStringMap(utils.OUT, utils.IN), BalanceWeight: 10, }, &ActionTrigger{ Id: "TestTR5", - ThresholdType: TRIGGER_MAX_BALANCE, + ThresholdType: utils.TRIGGER_MAX_BALANCE, BalanceType: utils.SMS, BalanceDirections: utils.NewStringMap(utils.OUT, utils.IN), BalanceWeight: 10, @@ -1535,42 +1535,42 @@ func TestAccountDoubleInitCounters(t *testing.T) { ActionTriggers: ActionTriggers{ &ActionTrigger{ Id: "TestTR1", - ThresholdType: TRIGGER_MAX_EVENT_COUNTER, + ThresholdType: utils.TRIGGER_MAX_EVENT_COUNTER, BalanceType: utils.MONETARY, BalanceDirections: utils.NewStringMap(utils.OUT, utils.IN), BalanceWeight: 10, }, &ActionTrigger{ Id: "TestTR11", - ThresholdType: TRIGGER_MAX_EVENT_COUNTER, + ThresholdType: utils.TRIGGER_MAX_EVENT_COUNTER, BalanceType: utils.MONETARY, BalanceDirections: utils.NewStringMap(utils.OUT, utils.IN), BalanceWeight: 10, }, &ActionTrigger{ Id: "TestTR2", - ThresholdType: TRIGGER_MAX_EVENT_COUNTER, + ThresholdType: utils.TRIGGER_MAX_EVENT_COUNTER, BalanceType: utils.VOICE, BalanceDirections: utils.NewStringMap(utils.OUT, utils.IN), BalanceWeight: 10, }, &ActionTrigger{ Id: "TestTR3", - ThresholdType: TRIGGER_MAX_BALANCE_COUNTER, + ThresholdType: utils.TRIGGER_MAX_BALANCE_COUNTER, BalanceType: utils.VOICE, BalanceDirections: utils.NewStringMap(utils.OUT, utils.IN), BalanceWeight: 10, }, &ActionTrigger{ Id: "TestTR4", - ThresholdType: TRIGGER_MAX_BALANCE_COUNTER, + ThresholdType: utils.TRIGGER_MAX_BALANCE_COUNTER, BalanceType: utils.SMS, BalanceDirections: utils.NewStringMap(utils.OUT, utils.IN), BalanceWeight: 10, }, &ActionTrigger{ Id: "TestTR5", - ThresholdType: TRIGGER_MAX_BALANCE, + ThresholdType: utils.TRIGGER_MAX_BALANCE, BalanceType: utils.SMS, BalanceDirections: utils.NewStringMap(utils.OUT, utils.IN), BalanceWeight: 10, diff --git a/engine/action_trigger.go b/engine/action_trigger.go index 72cc86441..79bebb3dd 100644 --- a/engine/action_trigger.go +++ b/engine/action_trigger.go @@ -31,7 +31,7 @@ import ( type ActionTrigger struct { Id string // for visual identification - ThresholdType string //*min_counter, *max_counter, *min_balance, *max_balance + 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 eexcuted flag each run diff --git a/engine/actions_test.go b/engine/actions_test.go index 320977ae3..eb4de9d71 100644 --- a/engine/actions_test.go +++ b/engine/actions_test.go @@ -516,7 +516,7 @@ func TestActionTriggerMatchNil(t *testing.T) { at := &ActionTrigger{ BalanceDirections: utils.NewStringMap(utils.OUT), BalanceType: utils.MONETARY, - ThresholdType: TRIGGER_MAX_BALANCE, + ThresholdType: utils.TRIGGER_MAX_BALANCE, ThresholdValue: 2, } var a *Action @@ -529,7 +529,7 @@ func TestActionTriggerMatchAllBlank(t *testing.T) { at := &ActionTrigger{ BalanceDirections: utils.NewStringMap(utils.OUT), BalanceType: utils.MONETARY, - ThresholdType: TRIGGER_MAX_BALANCE, + ThresholdType: utils.TRIGGER_MAX_BALANCE, ThresholdValue: 2, } a := &Action{} @@ -542,7 +542,7 @@ func TestActionTriggerMatchMinuteBucketBlank(t *testing.T) { at := &ActionTrigger{ BalanceDirections: utils.NewStringMap(utils.OUT), BalanceType: utils.MONETARY, - ThresholdType: TRIGGER_MAX_BALANCE, + ThresholdType: utils.TRIGGER_MAX_BALANCE, ThresholdValue: 2, } a := &Action{BalanceType: utils.MONETARY, ExtraParameters: `{"BalanceDirections":"*out"}`} @@ -555,10 +555,10 @@ func TestActionTriggerMatchMinuteBucketFull(t *testing.T) { at := &ActionTrigger{ BalanceDirections: utils.NewStringMap(utils.OUT), BalanceType: utils.MONETARY, - ThresholdType: TRIGGER_MAX_BALANCE, + ThresholdType: utils.TRIGGER_MAX_BALANCE, ThresholdValue: 2, } - a := &Action{ExtraParameters: fmt.Sprintf(`{"ThresholdType":"%v", "ThresholdValue": %v}`, TRIGGER_MAX_BALANCE, 2)} + a := &Action{ExtraParameters: fmt.Sprintf(`{"ThresholdType":"%v", "ThresholdValue": %v}`, utils.TRIGGER_MAX_BALANCE, 2)} if !at.Match(a) { t.Errorf("Action trigger [%v] does not match action [%v]", at, a) } @@ -568,10 +568,10 @@ func TestActionTriggerMatchAllFull(t *testing.T) { at := &ActionTrigger{ BalanceDirections: utils.NewStringMap(utils.OUT), BalanceType: utils.MONETARY, - ThresholdType: TRIGGER_MAX_BALANCE, + ThresholdType: utils.TRIGGER_MAX_BALANCE, ThresholdValue: 2, } - a := &Action{BalanceType: utils.MONETARY, ExtraParameters: fmt.Sprintf(`{"ThresholdType":"%v", "ThresholdValue": %v, "BalanceDirections":"*out"}`, TRIGGER_MAX_BALANCE, 2)} + a := &Action{BalanceType: utils.MONETARY, ExtraParameters: fmt.Sprintf(`{"ThresholdType":"%v", "ThresholdValue": %v, "BalanceDirections":"*out"}`, utils.TRIGGER_MAX_BALANCE, 2)} if !at.Match(a) { t.Errorf("Action trigger [%v] does not match action [%v]", at, a) } @@ -581,10 +581,10 @@ func TestActionTriggerMatchSomeFalse(t *testing.T) { at := &ActionTrigger{ BalanceDirections: utils.NewStringMap(utils.OUT), BalanceType: utils.MONETARY, - ThresholdType: TRIGGER_MAX_BALANCE, + ThresholdType: utils.TRIGGER_MAX_BALANCE, ThresholdValue: 2, } - a := &Action{BalanceType: utils.MONETARY, ExtraParameters: fmt.Sprintf(`{"ThresholdType":"%v", "ThresholdValue": %v, "BalanceDirections":"*in"}`, TRIGGER_MAX_BALANCE, 2)} + a := &Action{BalanceType: utils.MONETARY, ExtraParameters: fmt.Sprintf(`{"ThresholdType":"%v", "ThresholdValue": %v, "BalanceDirections":"*in"}`, utils.TRIGGER_MAX_BALANCE, 2)} if at.Match(a) { t.Errorf("Action trigger [%v] does not match action [%v]", at, a) } @@ -594,10 +594,10 @@ func TestActionTriggerMatcBalanceFalse(t *testing.T) { at := &ActionTrigger{ BalanceDirections: utils.NewStringMap(utils.OUT), BalanceType: utils.MONETARY, - ThresholdType: TRIGGER_MAX_BALANCE, + ThresholdType: utils.TRIGGER_MAX_BALANCE, ThresholdValue: 2, } - a := &Action{BalanceType: utils.MONETARY, ExtraParameters: fmt.Sprintf(`{"ThresholdType":"%v", "ThresholdValue": %v, "BalanceDirections":"*out"}`, TRIGGER_MAX_BALANCE, 3.0)} + a := &Action{BalanceType: utils.MONETARY, ExtraParameters: fmt.Sprintf(`{"ThresholdType":"%v", "ThresholdValue": %v, "BalanceDirections":"*out"}`, utils.TRIGGER_MAX_BALANCE, 3.0)} if at.Match(a) { t.Errorf("Action trigger [%v] does not match action [%v]", at, a) } @@ -607,10 +607,10 @@ func TestActionTriggerMatcAllFalse(t *testing.T) { at := &ActionTrigger{ BalanceDirections: utils.NewStringMap(utils.OUT), BalanceType: utils.MONETARY, - ThresholdType: TRIGGER_MAX_BALANCE, + ThresholdType: utils.TRIGGER_MAX_BALANCE, ThresholdValue: 2, } - a := &Action{BalanceType: utils.VOICE, ExtraParameters: fmt.Sprintf(`{"ThresholdType":"%v", "ThresholdValue": %v, "BalanceDirections":"*in"}`, TRIGGER_MAX_EVENT_COUNTER, 3)} + a := &Action{BalanceType: utils.VOICE, ExtraParameters: fmt.Sprintf(`{"ThresholdType":"%v", "ThresholdValue": %v, "BalanceDirections":"*in"}`, utils.TRIGGER_MAX_EVENT_COUNTER, 3)} if at.Match(a) { t.Errorf("Action trigger [%v] does not match action [%v]", at, a) } @@ -620,14 +620,14 @@ func TestActionTriggerMatchAll(t *testing.T) { at := &ActionTrigger{ BalanceDirections: utils.NewStringMap(utils.OUT), BalanceType: utils.MONETARY, - ThresholdType: TRIGGER_MAX_BALANCE, + ThresholdType: utils.TRIGGER_MAX_BALANCE, ThresholdValue: 2, BalanceDestinationIds: utils.NewStringMap("NAT"), BalanceWeight: 1.0, BalanceRatingSubject: "test1", BalanceSharedGroups: utils.NewStringMap("test2"), } - a := &Action{BalanceType: utils.MONETARY, ExtraParameters: fmt.Sprintf(`{"BalanceDirections":"*out", "ThresholdType":"%v", "ThresholdValue": %v, "DestinationIds": "%v", "BalanceWeight": %v, "BalanceRatingSubject": "%v", "BalanceSharedGroup": "%v"}`, TRIGGER_MAX_BALANCE, 2, "NAT", 1.0, "test1", "test2")} + a := &Action{BalanceType: utils.MONETARY, ExtraParameters: fmt.Sprintf(`{"BalanceDirections":"*out", "ThresholdType":"%v", "ThresholdValue": %v, "DestinationIds": "%v", "BalanceWeight": %v, "BalanceRatingSubject": "%v", "BalanceSharedGroup": "%v"}`, utils.TRIGGER_MAX_BALANCE, 2, "NAT", 1.0, "test1", "test2")} if !at.Match(a) { t.Errorf("Action trigger [%v] does not match action [%v]", at, a) } @@ -926,7 +926,7 @@ func TestActionResetAllCounters(t *testing.T) { &Balance{Value: 10, Weight: 20, DestinationIds: utils.NewStringMap("NAT"), Directions: utils.NewStringMap(utils.OUT)}, &Balance{Weight: 10, DestinationIds: utils.NewStringMap("RET"), Directions: utils.NewStringMap(utils.OUT)}}}, - ActionTriggers: ActionTriggers{&ActionTrigger{ThresholdType: TRIGGER_MAX_EVENT_COUNTER, BalanceType: utils.MONETARY, ThresholdValue: 2, BalanceDestinationIds: utils.NewStringMap("NAT"), BalanceWeight: 20, ActionsId: "TEST_ACTIONS", Executed: true}}, + ActionTriggers: ActionTriggers{&ActionTrigger{ThresholdType: utils.TRIGGER_MAX_EVENT_COUNTER, BalanceType: utils.MONETARY, ThresholdValue: 2, BalanceDestinationIds: utils.NewStringMap("NAT"), BalanceWeight: 20, ActionsId: "TEST_ACTIONS", Executed: true}}, } ub.InitCounters() resetCountersAction(ub, nil, nil, nil) @@ -954,7 +954,7 @@ func TestActionResetCounterOnlyDefault(t *testing.T) { BalanceMap: map[string]BalanceChain{ utils.MONETARY: BalanceChain{&Balance{Value: 100}}, utils.VOICE: BalanceChain{&Balance{Value: 10, Weight: 20, DestinationIds: utils.NewStringMap("NAT")}, &Balance{Weight: 10, DestinationIds: utils.NewStringMap("RET")}}}, - ActionTriggers: ActionTriggers{&ActionTrigger{BalanceType: utils.MONETARY, ThresholdType: TRIGGER_MAX_EVENT_COUNTER, ThresholdValue: 2, ActionsId: "TEST_ACTIONS", Executed: true}}, + ActionTriggers: ActionTriggers{&ActionTrigger{BalanceType: utils.MONETARY, ThresholdType: utils.TRIGGER_MAX_EVENT_COUNTER, ThresholdValue: 2, ActionsId: "TEST_ACTIONS", Executed: true}}, } a := &Action{BalanceType: utils.MONETARY} ub.InitCounters() @@ -1019,7 +1019,7 @@ func TestActionTriggerLogging(t *testing.T) { for k, v := range atMap { _ = k _ = v - /*if strings.Contains(k, LOG_ACTION_TRIGGER_PREFIX) && strings.Contains(v, expected) { + /*if strings.Contains(k, LOG_ACTION_utils.TRIGGER_PREFIX) && strings.Contains(v, expected) { key = k break }*/ diff --git a/engine/loader_csv_test.go b/engine/loader_csv_test.go index 5fef65033..86520b32d 100644 --- a/engine/loader_csv_test.go +++ b/engine/loader_csv_test.go @@ -1011,7 +1011,7 @@ func TestLoadActionTriggers(t *testing.T) { expected := &ActionTrigger{ BalanceType: utils.VOICE, BalanceDirections: utils.NewStringMap(utils.OUT), - ThresholdType: TRIGGER_MIN_EVENT_COUNTER, + ThresholdType: utils.TRIGGER_MIN_EVENT_COUNTER, ThresholdValue: 10, BalanceDestinationIds: utils.NewStringMap("GERMANY_O2"), BalanceCategories: utils.StringMap{}, @@ -1028,7 +1028,7 @@ func TestLoadActionTriggers(t *testing.T) { expected = &ActionTrigger{ BalanceType: utils.VOICE, BalanceDirections: utils.NewStringMap(utils.OUT), - ThresholdType: TRIGGER_MAX_BALANCE, + ThresholdType: utils.TRIGGER_MAX_BALANCE, ThresholdValue: 200, BalanceDestinationIds: utils.NewStringMap("GERMANY"), BalanceCategories: utils.StringMap{}, diff --git a/engine/units_counter_test.go b/engine/units_counter_test.go index a8ec56785..018676d4f 100644 --- a/engine/units_counter_test.go +++ b/engine/units_counter_test.go @@ -51,42 +51,42 @@ func TestUnitCountersCountAllMonetary(t *testing.T) { ActionTriggers: ActionTriggers{ &ActionTrigger{ Id: "TestTR1", - ThresholdType: TRIGGER_MAX_EVENT_COUNTER, + ThresholdType: utils.TRIGGER_MAX_EVENT_COUNTER, BalanceType: utils.MONETARY, BalanceDirections: utils.NewStringMap(utils.OUT, utils.IN), BalanceWeight: 10, }, &ActionTrigger{ Id: "TestTR11", - ThresholdType: TRIGGER_MAX_EVENT_COUNTER, + ThresholdType: utils.TRIGGER_MAX_EVENT_COUNTER, BalanceType: utils.MONETARY, BalanceDirections: utils.NewStringMap(utils.OUT, utils.IN), BalanceWeight: 10, }, &ActionTrigger{ Id: "TestTR2", - ThresholdType: TRIGGER_MAX_EVENT_COUNTER, + ThresholdType: utils.TRIGGER_MAX_EVENT_COUNTER, BalanceType: utils.VOICE, BalanceDirections: utils.NewStringMap(utils.OUT, utils.IN), BalanceWeight: 10, }, &ActionTrigger{ Id: "TestTR3", - ThresholdType: TRIGGER_MAX_BALANCE_COUNTER, + ThresholdType: utils.TRIGGER_MAX_BALANCE_COUNTER, BalanceType: utils.VOICE, BalanceDirections: utils.NewStringMap(utils.OUT, utils.IN), BalanceWeight: 10, }, &ActionTrigger{ Id: "TestTR4", - ThresholdType: TRIGGER_MAX_BALANCE_COUNTER, + ThresholdType: utils.TRIGGER_MAX_BALANCE_COUNTER, BalanceType: utils.SMS, BalanceDirections: utils.NewStringMap(utils.OUT, utils.IN), BalanceWeight: 10, }, &ActionTrigger{ Id: "TestTR5", - ThresholdType: TRIGGER_MAX_BALANCE, + ThresholdType: utils.TRIGGER_MAX_BALANCE, BalanceType: utils.SMS, BalanceDirections: utils.NewStringMap(utils.OUT, utils.IN), BalanceWeight: 10, @@ -115,42 +115,42 @@ func TestUnitCountersCountAllMonetaryId(t *testing.T) { ActionTriggers: ActionTriggers{ &ActionTrigger{ Id: "TestTR1", - ThresholdType: TRIGGER_MAX_BALANCE_COUNTER, + ThresholdType: utils.TRIGGER_MAX_BALANCE_COUNTER, BalanceType: utils.MONETARY, BalanceDirections: utils.NewStringMap(utils.OUT), BalanceWeight: 10, }, &ActionTrigger{ Id: "TestTR11", - ThresholdType: TRIGGER_MAX_BALANCE_COUNTER, + ThresholdType: utils.TRIGGER_MAX_BALANCE_COUNTER, BalanceType: utils.MONETARY, BalanceDirections: utils.NewStringMap(utils.OUT), BalanceWeight: 20, }, &ActionTrigger{ Id: "TestTR2", - ThresholdType: TRIGGER_MAX_EVENT_COUNTER, + ThresholdType: utils.TRIGGER_MAX_EVENT_COUNTER, BalanceType: utils.VOICE, BalanceDirections: utils.NewStringMap(utils.OUT), BalanceWeight: 10, }, &ActionTrigger{ Id: "TestTR3", - ThresholdType: TRIGGER_MAX_BALANCE_COUNTER, + ThresholdType: utils.TRIGGER_MAX_BALANCE_COUNTER, BalanceType: utils.VOICE, BalanceDirections: utils.NewStringMap(utils.OUT), BalanceWeight: 10, }, &ActionTrigger{ Id: "TestTR4", - ThresholdType: TRIGGER_MAX_BALANCE_COUNTER, + ThresholdType: utils.TRIGGER_MAX_BALANCE_COUNTER, BalanceType: utils.SMS, BalanceDirections: utils.NewStringMap(utils.OUT), BalanceWeight: 10, }, &ActionTrigger{ Id: "TestTR5", - ThresholdType: TRIGGER_MAX_BALANCE, + ThresholdType: utils.TRIGGER_MAX_BALANCE, BalanceType: utils.SMS, BalanceDirections: utils.NewStringMap(utils.OUT), BalanceWeight: 10, @@ -179,21 +179,21 @@ func TestUnitCountersCountAllVoiceDestinationEvent(t *testing.T) { ActionTriggers: ActionTriggers{ &ActionTrigger{ Id: "TestTR1", - ThresholdType: TRIGGER_MAX_BALANCE_COUNTER, + ThresholdType: utils.TRIGGER_MAX_BALANCE_COUNTER, BalanceType: utils.MONETARY, BalanceDirections: utils.NewStringMap(utils.OUT), BalanceWeight: 10, }, &ActionTrigger{ Id: "TestTR11", - ThresholdType: TRIGGER_MAX_BALANCE_COUNTER, + ThresholdType: utils.TRIGGER_MAX_BALANCE_COUNTER, BalanceType: utils.MONETARY, BalanceDirections: utils.NewStringMap(utils.OUT), BalanceWeight: 20, }, &ActionTrigger{ Id: "TestTR2", - ThresholdType: TRIGGER_MAX_EVENT_COUNTER, + ThresholdType: utils.TRIGGER_MAX_EVENT_COUNTER, BalanceType: utils.VOICE, BalanceDirections: utils.NewStringMap(utils.OUT), BalanceDestinationIds: utils.NewStringMap("NAT"), @@ -201,28 +201,28 @@ func TestUnitCountersCountAllVoiceDestinationEvent(t *testing.T) { }, &ActionTrigger{ Id: "TestTR22", - ThresholdType: TRIGGER_MAX_EVENT_COUNTER, + ThresholdType: utils.TRIGGER_MAX_EVENT_COUNTER, BalanceType: utils.VOICE, BalanceDestinationIds: utils.NewStringMap("RET"), BalanceWeight: 10, }, &ActionTrigger{ Id: "TestTR3", - ThresholdType: TRIGGER_MAX_BALANCE_COUNTER, + ThresholdType: utils.TRIGGER_MAX_BALANCE_COUNTER, BalanceType: utils.VOICE, BalanceDirections: utils.NewStringMap(utils.OUT), BalanceWeight: 10, }, &ActionTrigger{ Id: "TestTR4", - ThresholdType: TRIGGER_MAX_BALANCE_COUNTER, + ThresholdType: utils.TRIGGER_MAX_BALANCE_COUNTER, BalanceType: utils.SMS, BalanceDirections: utils.NewStringMap(utils.OUT), BalanceWeight: 10, }, &ActionTrigger{ Id: "TestTR5", - ThresholdType: TRIGGER_MAX_BALANCE, + ThresholdType: utils.TRIGGER_MAX_BALANCE, BalanceType: utils.SMS, BalanceDirections: utils.NewStringMap(utils.OUT), BalanceWeight: 10, diff --git a/utils/consts.go b/utils/consts.go index d4bce92d4..eec5f79fd 100644 --- a/utils/consts.go +++ b/utils/consts.go @@ -246,6 +246,14 @@ const ( CGR_SESSION_UPDATE = "CgrSessionUpdate" CGR_SESSION_END = "CgrSessionEnd" CGR_LCR_REQUEST = "CgrLcrRequest" + // action trigger threshold types + TRIGGER_MIN_EVENT_COUNTER = "*min_event_counter" + TRIGGER_MIN_BALANCE_COUNTER = "*min_balance_counter" + TRIGGER_MAX_EVENT_COUNTER = "*max_event_counter" + TRIGGER_MAX_BALANCE_COUNTER = "*max_balance_counter" + TRIGGER_MIN_BALANCE = "*min_balance" + TRIGGER_MAX_BALANCE = "*max_balance" + TRIGGER_EXP_BALANCE = "*exp_balance" ) var (