ID and UniqueID for action trigger

This commit is contained in:
Radu Ioan Fericean
2015-12-15 17:56:44 +02:00
parent d11d9eadb7
commit d5ab7e2a5e
10 changed files with 67 additions and 65 deletions

View File

@@ -783,7 +783,7 @@ func (acc *Account) AsOldStructure() interface{} {
}
for i, at := range acc.ActionTriggers {
result.ActionTriggers[i] = &ActionTrigger{
Id: at.Id,
Id: at.ID,
ThresholdType: at.ThresholdType,
ThresholdValue: at.ThresholdValue,
Recurrent: at.Recurrent,

View File

@@ -945,8 +945,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: 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"},
&ActionTrigger{UniqueID: "day_trigger", BalanceType: utils.MONETARY, BalanceDirections: utils.StringMap{utils.OUT: true}, ThresholdValue: 10, ThresholdType: utils.TRIGGER_MAX_EVENT_COUNTER, ActionsId: "TEST_ACTIONS"},
&ActionTrigger{UniqueID: "week_trigger", BalanceType: utils.MONETARY, BalanceDirections: utils.StringMap{utils.OUT: true}, ThresholdValue: 100, ThresholdType: utils.TRIGGER_MAX_EVENT_COUNTER, ActionsId: "TEST_ACTIONS"},
},
}
ub.InitCounters()
@@ -973,7 +973,7 @@ func TestAccountExpActionTrigger(t *testing.T) {
Id: "TEST_UB",
BalanceMap: map[string]BalanceChain{utils.MONETARY: BalanceChain{&Balance{Directions: utils.NewStringMap(utils.OUT), Value: 100, ExpirationDate: time.Date(2015, time.November, 9, 9, 48, 0, 0, time.UTC)}}, 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: "check expired balances", BalanceType: utils.MONETARY, BalanceDirections: utils.StringMap{utils.OUT: true}, ThresholdValue: 10, ThresholdType: utils.TRIGGER_BALANCE_EXPIRED, ActionsId: "TEST_ACTIONS"},
&ActionTrigger{ID: "check expired balances", BalanceType: utils.MONETARY, BalanceDirections: utils.StringMap{utils.OUT: true}, ThresholdValue: 10, ThresholdType: utils.TRIGGER_BALANCE_EXPIRED, ActionsId: "TEST_ACTIONS"},
},
}
ub.executeActionTriggers(nil)
@@ -1518,42 +1518,42 @@ func TestAccountInitCounters(t *testing.T) {
a := &Account{
ActionTriggers: ActionTriggers{
&ActionTrigger{
Id: "TestTR1",
UniqueID: "TestTR1",
ThresholdType: utils.TRIGGER_MAX_EVENT_COUNTER,
BalanceType: utils.MONETARY,
BalanceDirections: utils.NewStringMap(utils.OUT, utils.IN),
BalanceWeight: 10,
},
&ActionTrigger{
Id: "TestTR11",
UniqueID: "TestTR11",
ThresholdType: utils.TRIGGER_MAX_EVENT_COUNTER,
BalanceType: utils.MONETARY,
BalanceDirections: utils.NewStringMap(utils.OUT, utils.IN),
BalanceWeight: 10,
},
&ActionTrigger{
Id: "TestTR2",
UniqueID: "TestTR2",
ThresholdType: utils.TRIGGER_MAX_EVENT_COUNTER,
BalanceType: utils.VOICE,
BalanceDirections: utils.NewStringMap(utils.OUT, utils.IN),
BalanceWeight: 10,
},
&ActionTrigger{
Id: "TestTR3",
UniqueID: "TestTR3",
ThresholdType: utils.TRIGGER_MAX_BALANCE_COUNTER,
BalanceType: utils.VOICE,
BalanceDirections: utils.NewStringMap(utils.OUT, utils.IN),
BalanceWeight: 10,
},
&ActionTrigger{
Id: "TestTR4",
UniqueID: "TestTR4",
ThresholdType: utils.TRIGGER_MAX_BALANCE_COUNTER,
BalanceType: utils.SMS,
BalanceDirections: utils.NewStringMap(utils.OUT, utils.IN),
BalanceWeight: 10,
},
&ActionTrigger{
Id: "TestTR5",
UniqueID: "TestTR5",
ThresholdType: utils.TRIGGER_MAX_BALANCE,
BalanceType: utils.SMS,
BalanceDirections: utils.NewStringMap(utils.OUT, utils.IN),
@@ -1581,42 +1581,42 @@ func TestAccountDoubleInitCounters(t *testing.T) {
a := &Account{
ActionTriggers: ActionTriggers{
&ActionTrigger{
Id: "TestTR1",
UniqueID: "TestTR1",
ThresholdType: utils.TRIGGER_MAX_EVENT_COUNTER,
BalanceType: utils.MONETARY,
BalanceDirections: utils.NewStringMap(utils.OUT, utils.IN),
BalanceWeight: 10,
},
&ActionTrigger{
Id: "TestTR11",
UniqueID: "TestTR11",
ThresholdType: utils.TRIGGER_MAX_EVENT_COUNTER,
BalanceType: utils.MONETARY,
BalanceDirections: utils.NewStringMap(utils.OUT, utils.IN),
BalanceWeight: 10,
},
&ActionTrigger{
Id: "TestTR2",
UniqueID: "TestTR2",
ThresholdType: utils.TRIGGER_MAX_EVENT_COUNTER,
BalanceType: utils.VOICE,
BalanceDirections: utils.NewStringMap(utils.OUT, utils.IN),
BalanceWeight: 10,
},
&ActionTrigger{
Id: "TestTR3",
UniqueID: "TestTR3",
ThresholdType: utils.TRIGGER_MAX_BALANCE_COUNTER,
BalanceType: utils.VOICE,
BalanceDirections: utils.NewStringMap(utils.OUT, utils.IN),
BalanceWeight: 10,
},
&ActionTrigger{
Id: "TestTR4",
UniqueID: "TestTR4",
ThresholdType: utils.TRIGGER_MAX_BALANCE_COUNTER,
BalanceType: utils.SMS,
BalanceDirections: utils.NewStringMap(utils.OUT, utils.IN),
BalanceWeight: 10,
},
&ActionTrigger{
Id: "TestTR5",
UniqueID: "TestTR5",
ThresholdType: utils.TRIGGER_MAX_BALANCE,
BalanceType: utils.SMS,
BalanceDirections: utils.NewStringMap(utils.OUT, utils.IN),

View File

@@ -29,8 +29,8 @@ import (
)
type ActionTrigger struct {
Id string // for visual identification
Uuid string
ID string // original csv tag
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
@@ -154,7 +154,7 @@ func (at *ActionTrigger) Match(a *Action) bool {
}
// if we have Id than we can draw an early conclusion
if a.Id != "" {
match, _ := regexp.MatchString(a.Id, at.Id)
match, _ := regexp.MatchString(a.Id, at.ID)
return match
}
id := a.BalanceType == "" || at.BalanceType == a.BalanceType
@@ -196,7 +196,7 @@ func (at *ActionTrigger) Clone() *ActionTrigger {
func (at *ActionTrigger) CreateBalance() *Balance {
return &Balance{
Id: at.Id,
Id: at.UniqueID,
Directions: at.BalanceDirections,
ExpirationDate: at.BalanceExpirationDate,
DestinationIds: at.BalanceDestinationIds,
@@ -228,15 +228,3 @@ func (atpl ActionTriggers) Less(j, i int) bool {
func (atpl ActionTriggers) Sort() {
sort.Sort(atpl)
}
// clone with new id(uuid)
func (atrs ActionTriggers) Clone() ActionTriggers {
// set ids to action triggers
var newATriggers ActionTriggers
for _, atr := range atrs {
newAtr := atr.Clone()
newAtr.Uuid = utils.GenUUID()
newATriggers = append(newATriggers, newAtr)
}
return newATriggers
}

View File

@@ -1012,7 +1012,7 @@ func TestActionResetCounterCredit(t *testing.T) {
func TestActionTriggerLogging(t *testing.T) {
at := &ActionTrigger{
Id: "some_uuid",
ID: "some_uuid",
BalanceType: utils.MONETARY,
BalanceDirections: utils.NewStringMap(utils.OUT),
ThresholdValue: 100.0,

View File

@@ -1013,7 +1013,8 @@ func TestLoadActionTriggers(t *testing.T) {
}
atr := csvr.actionsTriggers["STANDARD_TRIGGER"][0]
expected := &ActionTrigger{
Id: "STANDARD_TRIGGER",
ID: "STANDARD_TRIGGER",
UniqueID: "st0",
BalanceType: utils.VOICE,
BalanceDirections: utils.NewStringMap(utils.OUT),
ThresholdType: utils.TRIGGER_MIN_EVENT_COUNTER,
@@ -1031,7 +1032,8 @@ func TestLoadActionTriggers(t *testing.T) {
}
atr = csvr.actionsTriggers["STANDARD_TRIGGER"][1]
expected = &ActionTrigger{
Id: "STANDARD_TRIGGER",
ID: "STANDARD_TRIGGER",
UniqueID: "st1",
BalanceType: utils.VOICE,
BalanceDirections: utils.NewStringMap(utils.OUT),
ThresholdType: utils.TRIGGER_MAX_BALANCE,
@@ -1077,7 +1079,7 @@ func TestLoadAccountActions(t *testing.T) {
}
// set propper uuid
for i, atr := range aa.ActionTriggers {
csvr.actionsTriggers["STANDARD_TRIGGER"][i].Id = atr.Id
csvr.actionsTriggers["STANDARD_TRIGGER"][i].ID = atr.ID
}
for i, b := range aa.UnitCounters[0].Balances {
expected.UnitCounters[0].Balances[i].Id = b.Id

View File

@@ -421,7 +421,8 @@ func (tps TpActionTriggers) GetActionTriggers() (map[string][]*utils.TPActionTri
ats := make(map[string][]*utils.TPActionTrigger)
for _, tpAt := range tps {
at := &utils.TPActionTrigger{
Id: tpAt.UniqueId,
Id: tpAt.Tag,
UniqueID: tpAt.UniqueId,
ThresholdType: tpAt.ThresholdType,
ThresholdValue: tpAt.ThresholdValue,
Recurrent: tpAt.Recurrent,

View File

@@ -280,7 +280,7 @@ func GetUB() *Account {
Balances: BalanceChain{&Balance{Value: 1}, &Balance{Weight: 20, DestinationIds: utils.NewStringMap("NAT")}, &Balance{Weight: 10, DestinationIds: utils.NewStringMap("RET")}},
}
at := &ActionTrigger{
Id: "some_uuid",
ID: "some_uuid",
BalanceType: utils.MONETARY,
BalanceDirections: utils.NewStringMap(utils.OUT),
ThresholdValue: 100.0,

View File

@@ -614,8 +614,12 @@ func (tpr *TpReader) LoadActionTriggers() (err error) {
if err != nil {
return err
}
if atr.UniqueID == "" {
atr.UniqueID = utils.GenUUID()
}
atrs[idx] = &ActionTrigger{
Id: key,
ID: key,
UniqueID: atr.UniqueID,
ThresholdType: atr.ThresholdType,
ThresholdValue: atr.ThresholdValue,
Recurrent: atr.Recurrent,
@@ -754,9 +758,12 @@ func (tpr *TpReader) LoadAccountActionsFiltered(qriedAA *TpAccountAction) error
for idx, apiAtr := range atrsLst {
minSleep, _ := utils.ParseDurationWithSecs(apiAtr.MinSleep)
expTime, _ := utils.ParseDate(apiAtr.BalanceExpirationDate)
if apiAtr.UniqueID == "" {
apiAtr.UniqueID = utils.GenUUID()
}
atrs[idx] = &ActionTrigger{
Id: key,
Uuid: utils.GenUUID(),
ID: key,
UniqueID: apiAtr.UniqueID,
ThresholdType: apiAtr.ThresholdType,
ThresholdValue: apiAtr.ThresholdValue,
Recurrent: apiAtr.Recurrent,
@@ -836,7 +843,7 @@ func (tpr *TpReader) LoadAccountActionsFiltered(qriedAA *TpAccountAction) error
Id: id,
}
}
ub.ActionTriggers = actionTriggers.Clone()
ub.ActionTriggers = actionTriggers
// init counters
ub.InitCounters()
if err := tpr.accountingStorage.SetAccount(ub); err != nil {
@@ -870,7 +877,7 @@ func (tpr *TpReader) LoadAccountActions() (err error) {
ub := &Account{
Id: aa.KeyId(),
ActionTriggers: aTriggers.Clone(),
ActionTriggers: aTriggers,
AllowNegative: aa.AllowNegative,
Disabled: aa.Disabled,
}
@@ -966,9 +973,12 @@ func (tpr *TpReader) LoadCdrStatsFiltered(tag string, save bool) (err error) {
for idx, apiAtr := range atrsLst {
minSleep, _ := utils.ParseDurationWithSecs(apiAtr.MinSleep)
expTime, _ := utils.ParseDate(apiAtr.BalanceExpirationDate)
if apiAtr.UniqueID == "" {
apiAtr.UniqueID = utils.GenUUID()
}
atrs[idx] = &ActionTrigger{
Id: triggerTag,
Uuid: utils.GenUUID(),
ID: triggerTag,
UniqueID: apiAtr.UniqueID,
ThresholdType: apiAtr.ThresholdType,
ThresholdValue: apiAtr.ThresholdValue,
Recurrent: apiAtr.Recurrent,

View File

@@ -50,42 +50,42 @@ func TestUnitCountersCountAllMonetary(t *testing.T) {
a := &Account{
ActionTriggers: ActionTriggers{
&ActionTrigger{
Id: "TestTR1",
UniqueID: "TestTR1",
ThresholdType: utils.TRIGGER_MAX_EVENT_COUNTER,
BalanceType: utils.MONETARY,
BalanceDirections: utils.NewStringMap(utils.OUT, utils.IN),
BalanceWeight: 10,
},
&ActionTrigger{
Id: "TestTR11",
UniqueID: "TestTR11",
ThresholdType: utils.TRIGGER_MAX_EVENT_COUNTER,
BalanceType: utils.MONETARY,
BalanceDirections: utils.NewStringMap(utils.OUT, utils.IN),
BalanceWeight: 10,
},
&ActionTrigger{
Id: "TestTR2",
UniqueID: "TestTR2",
ThresholdType: utils.TRIGGER_MAX_EVENT_COUNTER,
BalanceType: utils.VOICE,
BalanceDirections: utils.NewStringMap(utils.OUT, utils.IN),
BalanceWeight: 10,
},
&ActionTrigger{
Id: "TestTR3",
UniqueID: "TestTR3",
ThresholdType: utils.TRIGGER_MAX_BALANCE_COUNTER,
BalanceType: utils.VOICE,
BalanceDirections: utils.NewStringMap(utils.OUT, utils.IN),
BalanceWeight: 10,
},
&ActionTrigger{
Id: "TestTR4",
UniqueID: "TestTR4",
ThresholdType: utils.TRIGGER_MAX_BALANCE_COUNTER,
BalanceType: utils.SMS,
BalanceDirections: utils.NewStringMap(utils.OUT, utils.IN),
BalanceWeight: 10,
},
&ActionTrigger{
Id: "TestTR5",
UniqueID: "TestTR5",
ThresholdType: utils.TRIGGER_MAX_BALANCE,
BalanceType: utils.SMS,
BalanceDirections: utils.NewStringMap(utils.OUT, utils.IN),
@@ -114,42 +114,42 @@ func TestUnitCountersCountAllMonetaryId(t *testing.T) {
a := &Account{
ActionTriggers: ActionTriggers{
&ActionTrigger{
Id: "TestTR1",
UniqueID: "TestTR1",
ThresholdType: utils.TRIGGER_MAX_BALANCE_COUNTER,
BalanceType: utils.MONETARY,
BalanceDirections: utils.NewStringMap(utils.OUT),
BalanceWeight: 10,
},
&ActionTrigger{
Id: "TestTR11",
UniqueID: "TestTR11",
ThresholdType: utils.TRIGGER_MAX_BALANCE_COUNTER,
BalanceType: utils.MONETARY,
BalanceDirections: utils.NewStringMap(utils.OUT),
BalanceWeight: 20,
},
&ActionTrigger{
Id: "TestTR2",
UniqueID: "TestTR2",
ThresholdType: utils.TRIGGER_MAX_EVENT_COUNTER,
BalanceType: utils.VOICE,
BalanceDirections: utils.NewStringMap(utils.OUT),
BalanceWeight: 10,
},
&ActionTrigger{
Id: "TestTR3",
UniqueID: "TestTR3",
ThresholdType: utils.TRIGGER_MAX_BALANCE_COUNTER,
BalanceType: utils.VOICE,
BalanceDirections: utils.NewStringMap(utils.OUT),
BalanceWeight: 10,
},
&ActionTrigger{
Id: "TestTR4",
UniqueID: "TestTR4",
ThresholdType: utils.TRIGGER_MAX_BALANCE_COUNTER,
BalanceType: utils.SMS,
BalanceDirections: utils.NewStringMap(utils.OUT),
BalanceWeight: 10,
},
&ActionTrigger{
Id: "TestTR5",
UniqueID: "TestTR5",
ThresholdType: utils.TRIGGER_MAX_BALANCE,
BalanceType: utils.SMS,
BalanceDirections: utils.NewStringMap(utils.OUT),
@@ -178,21 +178,21 @@ func TestUnitCountersCountAllVoiceDestinationEvent(t *testing.T) {
a := &Account{
ActionTriggers: ActionTriggers{
&ActionTrigger{
Id: "TestTR1",
UniqueID: "TestTR1",
ThresholdType: utils.TRIGGER_MAX_BALANCE_COUNTER,
BalanceType: utils.MONETARY,
BalanceDirections: utils.NewStringMap(utils.OUT),
BalanceWeight: 10,
},
&ActionTrigger{
Id: "TestTR11",
UniqueID: "TestTR11",
ThresholdType: utils.TRIGGER_MAX_BALANCE_COUNTER,
BalanceType: utils.MONETARY,
BalanceDirections: utils.NewStringMap(utils.OUT),
BalanceWeight: 20,
},
&ActionTrigger{
Id: "TestTR2",
UniqueID: "TestTR2",
ThresholdType: utils.TRIGGER_MAX_EVENT_COUNTER,
BalanceType: utils.VOICE,
BalanceDirections: utils.NewStringMap(utils.OUT),
@@ -200,28 +200,28 @@ func TestUnitCountersCountAllVoiceDestinationEvent(t *testing.T) {
BalanceWeight: 10,
},
&ActionTrigger{
Id: "TestTR22",
UniqueID: "TestTR22",
ThresholdType: utils.TRIGGER_MAX_EVENT_COUNTER,
BalanceType: utils.VOICE,
BalanceDestinationIds: utils.NewStringMap("RET"),
BalanceWeight: 10,
},
&ActionTrigger{
Id: "TestTR3",
UniqueID: "TestTR3",
ThresholdType: utils.TRIGGER_MAX_BALANCE_COUNTER,
BalanceType: utils.VOICE,
BalanceDirections: utils.NewStringMap(utils.OUT),
BalanceWeight: 10,
},
&ActionTrigger{
Id: "TestTR4",
UniqueID: "TestTR4",
ThresholdType: utils.TRIGGER_MAX_BALANCE_COUNTER,
BalanceType: utils.SMS,
BalanceDirections: utils.NewStringMap(utils.OUT),
BalanceWeight: 10,
},
&ActionTrigger{
Id: "TestTR5",
UniqueID: "TestTR5",
ThresholdType: utils.TRIGGER_MAX_BALANCE,
BalanceType: utils.SMS,
BalanceDirections: utils.NewStringMap(utils.OUT),