mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-23 08:08:45 +05:00
normal engine tests passing
This commit is contained in:
@@ -37,7 +37,7 @@ var (
|
||||
)
|
||||
|
||||
func TestActionTimingAlways(t *testing.T) {
|
||||
at := &ActionTiming{Timing: &RateInterval{Timing: &RITiming{StartTime: "00:00:00"}}}
|
||||
at := &ActionPlan{Timing: &RateInterval{Timing: &RITiming{StartTime: "00:00:00"}}}
|
||||
st := at.GetNextStartTime(referenceDate)
|
||||
y, m, d := referenceDate.Date()
|
||||
expected := time.Date(y, m, d, 0, 0, 0, 0, time.Local).AddDate(0, 0, 1)
|
||||
@@ -46,8 +46,8 @@ func TestActionTimingAlways(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestActionTimingNothing(t *testing.T) {
|
||||
at := &ActionTiming{}
|
||||
func TestActionPlanNothing(t *testing.T) {
|
||||
at := &ActionPlan{}
|
||||
st := at.GetNextStartTime(referenceDate)
|
||||
expected := time.Date(1, 1, 1, 0, 0, 0, 0, time.UTC)
|
||||
if !st.Equal(expected) {
|
||||
@@ -55,8 +55,8 @@ func TestActionTimingNothing(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestActionTimingOnlyHour(t *testing.T) {
|
||||
at := &ActionTiming{Timing: &RateInterval{Timing: &RITiming{StartTime: "10:01:00"}}}
|
||||
func TestActionPlanOnlyHour(t *testing.T) {
|
||||
at := &ActionPlan{Timing: &RateInterval{Timing: &RITiming{StartTime: "10:01:00"}}}
|
||||
st := at.GetNextStartTime(referenceDate)
|
||||
|
||||
y, m, d := now.Date()
|
||||
@@ -69,8 +69,8 @@ func TestActionTimingOnlyHour(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestActionTimingHourYear(t *testing.T) {
|
||||
at := &ActionTiming{Timing: &RateInterval{Timing: &RITiming{Years: utils.Years{2022}, StartTime: "10:01:00"}}}
|
||||
func TestActionPlanHourYear(t *testing.T) {
|
||||
at := &ActionPlan{Timing: &RateInterval{Timing: &RITiming{Years: utils.Years{2022}, StartTime: "10:01:00"}}}
|
||||
st := at.GetNextStartTime(referenceDate)
|
||||
expected := time.Date(2022, 1, 1, 10, 1, 0, 0, time.Local)
|
||||
if !st.Equal(expected) {
|
||||
@@ -78,8 +78,8 @@ func TestActionTimingHourYear(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestActionTimingOnlyWeekdays(t *testing.T) {
|
||||
at := &ActionTiming{Timing: &RateInterval{Timing: &RITiming{WeekDays: []time.Weekday{time.Monday}}}}
|
||||
func TestActionPlanOnlyWeekdays(t *testing.T) {
|
||||
at := &ActionPlan{Timing: &RateInterval{Timing: &RITiming{WeekDays: []time.Weekday{time.Monday}}}}
|
||||
st := at.GetNextStartTime(referenceDate)
|
||||
|
||||
y, m, d := now.Date()
|
||||
@@ -99,8 +99,8 @@ func TestActionTimingOnlyWeekdays(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestActionTimingHourWeekdays(t *testing.T) {
|
||||
at := &ActionTiming{Timing: &RateInterval{Timing: &RITiming{WeekDays: []time.Weekday{time.Monday}, StartTime: "10:01:00"}}}
|
||||
func TestActionPlanHourWeekdays(t *testing.T) {
|
||||
at := &ActionPlan{Timing: &RateInterval{Timing: &RITiming{WeekDays: []time.Weekday{time.Monday}, StartTime: "10:01:00"}}}
|
||||
st := at.GetNextStartTime(referenceDate)
|
||||
|
||||
y, m, d := now.Date()
|
||||
@@ -119,11 +119,11 @@ func TestActionTimingHourWeekdays(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestActionTimingOnlyMonthdays(t *testing.T) {
|
||||
func TestActionPlanOnlyMonthdays(t *testing.T) {
|
||||
|
||||
y, m, d := now.Date()
|
||||
tomorrow := time.Date(y, m, d, 0, 0, 0, 0, time.Local).AddDate(0, 0, 1)
|
||||
at := &ActionTiming{Timing: &RateInterval{Timing: &RITiming{MonthDays: utils.MonthDays{1, 25, 2, tomorrow.Day()}}}}
|
||||
at := &ActionPlan{Timing: &RateInterval{Timing: &RITiming{MonthDays: utils.MonthDays{1, 25, 2, tomorrow.Day()}}}}
|
||||
st := at.GetNextStartTime(referenceDate)
|
||||
expected := tomorrow
|
||||
if !st.Equal(expected) {
|
||||
@@ -131,7 +131,7 @@ func TestActionTimingOnlyMonthdays(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestActionTimingHourMonthdays(t *testing.T) {
|
||||
func TestActionPlanHourMonthdays(t *testing.T) {
|
||||
|
||||
y, m, d := now.Date()
|
||||
testTime := time.Date(y, m, d, 10, 1, 0, 0, time.Local)
|
||||
@@ -139,7 +139,7 @@ func TestActionTimingHourMonthdays(t *testing.T) {
|
||||
if now.After(testTime) {
|
||||
y, m, d = tomorrow.Date()
|
||||
}
|
||||
at := &ActionTiming{Timing: &RateInterval{Timing: &RITiming{MonthDays: utils.MonthDays{now.Day(), tomorrow.Day()}, StartTime: "10:01:00"}}}
|
||||
at := &ActionPlan{Timing: &RateInterval{Timing: &RITiming{MonthDays: utils.MonthDays{now.Day(), tomorrow.Day()}, StartTime: "10:01:00"}}}
|
||||
st := at.GetNextStartTime(referenceDate)
|
||||
expected := time.Date(y, m, d, 10, 1, 0, 0, time.Local)
|
||||
if !st.Equal(expected) {
|
||||
@@ -147,11 +147,11 @@ func TestActionTimingHourMonthdays(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestActionTimingOnlyMonths(t *testing.T) {
|
||||
func TestActionPlanOnlyMonths(t *testing.T) {
|
||||
|
||||
y, m, _ := now.Date()
|
||||
nextMonth := time.Date(y, m, 1, 0, 0, 0, 0, time.Local).AddDate(0, 1, 0)
|
||||
at := &ActionTiming{Timing: &RateInterval{Timing: &RITiming{Months: utils.Months{time.February, time.May, nextMonth.Month()}}}}
|
||||
at := &ActionPlan{Timing: &RateInterval{Timing: &RITiming{Months: utils.Months{time.February, time.May, nextMonth.Month()}}}}
|
||||
st := at.GetNextStartTime(referenceDate)
|
||||
expected := time.Date(nextMonth.Year(), nextMonth.Month(), 1, 0, 0, 0, 0, time.Local)
|
||||
if !st.Equal(expected) {
|
||||
@@ -160,7 +160,7 @@ func TestActionTimingOnlyMonths(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestActionTimingHourMonths(t *testing.T) {
|
||||
func TestActionPlanHourMonths(t *testing.T) {
|
||||
|
||||
y, m, d := now.Date()
|
||||
testTime := time.Date(y, m, d, 10, 1, 0, 0, time.Local)
|
||||
@@ -174,7 +174,7 @@ func TestActionTimingHourMonths(t *testing.T) {
|
||||
y = nextMonth.Year()
|
||||
|
||||
}
|
||||
at := &ActionTiming{Timing: &RateInterval{Timing: &RITiming{
|
||||
at := &ActionPlan{Timing: &RateInterval{Timing: &RITiming{
|
||||
Months: utils.Months{now.Month(), nextMonth.Month()},
|
||||
StartTime: "10:01:00"}}}
|
||||
st := at.GetNextStartTime(referenceDate)
|
||||
@@ -187,7 +187,7 @@ func TestActionTimingHourMonths(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestActionTimingHourMonthdaysMonths(t *testing.T) {
|
||||
func TestActionPlanHourMonthdaysMonths(t *testing.T) {
|
||||
|
||||
y, m, d := now.Date()
|
||||
testTime := time.Date(y, m, d, 10, 1, 0, 0, time.Local)
|
||||
@@ -204,7 +204,7 @@ func TestActionTimingHourMonthdaysMonths(t *testing.T) {
|
||||
month = nextMonth.Month()
|
||||
}
|
||||
}
|
||||
at := &ActionTiming{Timing: &RateInterval{
|
||||
at := &ActionPlan{Timing: &RateInterval{
|
||||
Timing: &RITiming{
|
||||
Months: utils.Months{now.Month(), nextMonth.Month()},
|
||||
MonthDays: utils.MonthDays{now.Day(), tomorrow.Day()},
|
||||
@@ -218,11 +218,11 @@ func TestActionTimingHourMonthdaysMonths(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestActionTimingFirstOfTheMonth(t *testing.T) {
|
||||
func TestActionPlanFirstOfTheMonth(t *testing.T) {
|
||||
|
||||
y, m, _ := now.Date()
|
||||
nextMonth := time.Date(y, m, 1, 0, 0, 0, 0, time.Local).AddDate(0, 1, 0)
|
||||
at := &ActionTiming{Timing: &RateInterval{
|
||||
at := &ActionPlan{Timing: &RateInterval{
|
||||
Timing: &RITiming{
|
||||
MonthDays: utils.MonthDays{1},
|
||||
},
|
||||
@@ -234,10 +234,10 @@ func TestActionTimingFirstOfTheMonth(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestActionTimingOnlyYears(t *testing.T) {
|
||||
func TestActionPlanOnlyYears(t *testing.T) {
|
||||
y, _, _ := referenceDate.Date()
|
||||
nextYear := time.Date(y, 1, 1, 0, 0, 0, 0, time.Local).AddDate(1, 0, 0)
|
||||
at := &ActionTiming{Timing: &RateInterval{Timing: &RITiming{Years: utils.Years{now.Year(), nextYear.Year()}}}}
|
||||
at := &ActionPlan{Timing: &RateInterval{Timing: &RITiming{Years: utils.Years{now.Year(), nextYear.Year()}}}}
|
||||
st := at.GetNextStartTime(referenceDate)
|
||||
expected := nextYear
|
||||
if !st.Equal(expected) {
|
||||
@@ -245,8 +245,8 @@ func TestActionTimingOnlyYears(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestActionTimingPast(t *testing.T) {
|
||||
at := &ActionTiming{Timing: &RateInterval{Timing: &RITiming{Years: utils.Years{2023}}}}
|
||||
func TestActionPlanPast(t *testing.T) {
|
||||
at := &ActionPlan{Timing: &RateInterval{Timing: &RITiming{Years: utils.Years{2023}}}}
|
||||
st := at.GetNextStartTime(referenceDate)
|
||||
expected := time.Date(2023, 1, 1, 0, 0, 0, 0, time.Local)
|
||||
if !st.Equal(expected) {
|
||||
@@ -254,8 +254,8 @@ func TestActionTimingPast(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestActionTimingHourYears(t *testing.T) {
|
||||
at := &ActionTiming{Timing: &RateInterval{Timing: &RITiming{Years: utils.Years{referenceDate.Year(), referenceDate.Year() + 1}, StartTime: "10:01:00"}}}
|
||||
func TestActionPlanHourYears(t *testing.T) {
|
||||
at := &ActionPlan{Timing: &RateInterval{Timing: &RITiming{Years: utils.Years{referenceDate.Year(), referenceDate.Year() + 1}, StartTime: "10:01:00"}}}
|
||||
st := at.GetNextStartTime(referenceDate)
|
||||
expected := time.Date(referenceDate.Year(), 1, 1, 10, 1, 0, 0, time.Local)
|
||||
if referenceDate.After(expected) {
|
||||
@@ -266,7 +266,7 @@ func TestActionTimingHourYears(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestActionTimingHourMonthdaysYear(t *testing.T) {
|
||||
func TestActionPlanHourMonthdaysYear(t *testing.T) {
|
||||
|
||||
y, m, d := now.Date()
|
||||
testTime := time.Date(y, m, d, 10, 1, 0, 0, time.Local)
|
||||
@@ -280,7 +280,7 @@ func TestActionTimingHourMonthdaysYear(t *testing.T) {
|
||||
expected = tomorrow
|
||||
}
|
||||
}
|
||||
at := &ActionTiming{Timing: &RateInterval{
|
||||
at := &ActionPlan{Timing: &RateInterval{
|
||||
Timing: &RITiming{
|
||||
Years: utils.Years{now.Year(), nextYear.Year()},
|
||||
MonthDays: utils.MonthDays{now.Day(), tomorrow.Day()},
|
||||
@@ -295,7 +295,7 @@ func TestActionTimingHourMonthdaysYear(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestActionTimingHourMonthdaysMonthYear(t *testing.T) {
|
||||
func TestActionPlanHourMonthdaysMonthYear(t *testing.T) {
|
||||
|
||||
y, m, d := now.Date()
|
||||
testTime := time.Date(y, m, d, 10, 1, 0, 0, time.Local)
|
||||
@@ -320,7 +320,7 @@ func TestActionTimingHourMonthdaysMonthYear(t *testing.T) {
|
||||
year = nextYear.Year()
|
||||
}
|
||||
}
|
||||
at := &ActionTiming{Timing: &RateInterval{
|
||||
at := &ActionPlan{Timing: &RateInterval{
|
||||
Timing: &RITiming{
|
||||
Years: utils.Years{now.Year(), nextYear.Year()},
|
||||
Months: utils.Months{now.Month(), nextMonth.Month()},
|
||||
@@ -335,10 +335,10 @@ func TestActionTimingHourMonthdaysMonthYear(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestActionTimingFirstOfTheYear(t *testing.T) {
|
||||
func TestActionPlanFirstOfTheYear(t *testing.T) {
|
||||
y, _, _ := now.Date()
|
||||
nextYear := time.Date(y, 1, 1, 0, 0, 0, 0, time.Local).AddDate(1, 0, 0)
|
||||
at := &ActionTiming{Timing: &RateInterval{
|
||||
at := &ActionPlan{Timing: &RateInterval{
|
||||
Timing: &RITiming{
|
||||
Years: utils.Years{nextYear.Year()},
|
||||
Months: utils.Months{time.January},
|
||||
@@ -353,13 +353,13 @@ func TestActionTimingFirstOfTheYear(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestActionTimingFirstMonthOfTheYear(t *testing.T) {
|
||||
func TestActionPlanFirstMonthOfTheYear(t *testing.T) {
|
||||
y, _, _ := now.Date()
|
||||
expected := time.Date(y, 1, 1, 0, 0, 0, 0, time.Local)
|
||||
if referenceDate.After(expected) {
|
||||
expected = expected.AddDate(1, 0, 0)
|
||||
}
|
||||
at := &ActionTiming{Timing: &RateInterval{
|
||||
at := &ActionPlan{Timing: &RateInterval{
|
||||
Timing: &RITiming{
|
||||
Months: utils.Months{time.January},
|
||||
},
|
||||
@@ -370,13 +370,13 @@ func TestActionTimingFirstMonthOfTheYear(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestActionTimingFirstMonthOfTheYearSecondDay(t *testing.T) {
|
||||
func TestActionPlanFirstMonthOfTheYearSecondDay(t *testing.T) {
|
||||
y, _, _ := now.Date()
|
||||
expected := time.Date(y, 1, 2, 0, 0, 0, 0, time.Local)
|
||||
if referenceDate.After(expected) {
|
||||
expected = expected.AddDate(1, 0, 0)
|
||||
}
|
||||
at := &ActionTiming{Timing: &RateInterval{
|
||||
at := &ActionPlan{Timing: &RateInterval{
|
||||
Timing: &RITiming{
|
||||
Months: utils.Months{time.January},
|
||||
MonthDays: utils.MonthDays{2},
|
||||
@@ -388,20 +388,20 @@ func TestActionTimingFirstMonthOfTheYearSecondDay(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestActionTimingCheckForASAP(t *testing.T) {
|
||||
at := &ActionTiming{Timing: &RateInterval{Timing: &RITiming{StartTime: ASAP}}}
|
||||
func TestActionPlanCheckForASAP(t *testing.T) {
|
||||
at := &ActionPlan{Timing: &RateInterval{Timing: &RITiming{StartTime: ASAP}}}
|
||||
if !at.IsASAP() {
|
||||
t.Errorf("%v should be asap!", at)
|
||||
}
|
||||
}
|
||||
|
||||
func TestActionTimingLogFunction(t *testing.T) {
|
||||
func TestActionPlanLogFunction(t *testing.T) {
|
||||
a := &Action{
|
||||
ActionType: "*log",
|
||||
BalanceType: "test",
|
||||
Balance: &Balance{Value: 1.1},
|
||||
}
|
||||
at := &ActionTiming{
|
||||
at := &ActionPlan{
|
||||
actions: []*Action{a},
|
||||
}
|
||||
err := at.Execute()
|
||||
@@ -410,13 +410,13 @@ func TestActionTimingLogFunction(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestActionTimingFunctionNotAvailable(t *testing.T) {
|
||||
func TestActionPlanFunctionNotAvailable(t *testing.T) {
|
||||
a := &Action{
|
||||
ActionType: "VALID_FUNCTION_TYPE",
|
||||
BalanceType: "test",
|
||||
Balance: &Balance{Value: 1.1},
|
||||
}
|
||||
at := &ActionTiming{
|
||||
at := &ActionPlan{
|
||||
AccountIds: []string{"one", "two", "three"},
|
||||
Timing: &RateInterval{},
|
||||
actions: []*Action{a},
|
||||
@@ -427,8 +427,8 @@ func TestActionTimingFunctionNotAvailable(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestActionTimingPriotityListSortByWeight(t *testing.T) {
|
||||
at1 := &ActionTiming{Timing: &RateInterval{
|
||||
func TestActionPlanPriotityListSortByWeight(t *testing.T) {
|
||||
at1 := &ActionPlan{Timing: &RateInterval{
|
||||
Timing: &RITiming{
|
||||
Years: utils.Years{2020},
|
||||
Months: utils.Months{time.January, time.February, time.March, time.April, time.May, time.June, time.July, time.August, time.September, time.October, time.November, time.December},
|
||||
@@ -437,7 +437,7 @@ func TestActionTimingPriotityListSortByWeight(t *testing.T) {
|
||||
},
|
||||
Weight: 20,
|
||||
}}
|
||||
at2 := &ActionTiming{Timing: &RateInterval{
|
||||
at2 := &ActionPlan{Timing: &RateInterval{
|
||||
Timing: &RITiming{
|
||||
Years: utils.Years{2020},
|
||||
Months: utils.Months{time.January, time.February, time.March, time.April, time.May, time.June, time.July, time.August, time.September, time.October, time.November, time.December},
|
||||
@@ -446,7 +446,7 @@ func TestActionTimingPriotityListSortByWeight(t *testing.T) {
|
||||
},
|
||||
Weight: 10,
|
||||
}}
|
||||
var atpl ActionTimingPriotityList
|
||||
var atpl ActionPlanPriotityList
|
||||
atpl = append(atpl, at2, at1)
|
||||
atpl.Sort()
|
||||
if atpl[0] != at1 || atpl[1] != at2 {
|
||||
@@ -454,8 +454,8 @@ func TestActionTimingPriotityListSortByWeight(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestActionTimingPriotityListWeight(t *testing.T) {
|
||||
at1 := &ActionTiming{
|
||||
func TestActionPlanPriotityListWeight(t *testing.T) {
|
||||
at1 := &ActionPlan{
|
||||
Timing: &RateInterval{
|
||||
Timing: &RITiming{
|
||||
Months: utils.Months{time.January, time.February, time.March, time.April, time.May, time.June, time.July, time.August, time.September, time.October, time.November, time.December},
|
||||
@@ -465,7 +465,7 @@ func TestActionTimingPriotityListWeight(t *testing.T) {
|
||||
},
|
||||
Weight: 20,
|
||||
}
|
||||
at2 := &ActionTiming{
|
||||
at2 := &ActionPlan{
|
||||
Timing: &RateInterval{
|
||||
Timing: &RITiming{
|
||||
Months: utils.Months{time.January, time.February, time.March, time.April, time.May, time.June, time.July, time.August, time.September, time.October, time.November, time.December},
|
||||
@@ -475,7 +475,7 @@ func TestActionTimingPriotityListWeight(t *testing.T) {
|
||||
},
|
||||
Weight: 10,
|
||||
}
|
||||
var atpl ActionTimingPriotityList
|
||||
var atpl ActionPlanPriotityList
|
||||
atpl = append(atpl, at2, at1)
|
||||
atpl.Sort()
|
||||
if atpl[0] != at1 || atpl[1] != at2 {
|
||||
@@ -483,31 +483,31 @@ func TestActionTimingPriotityListWeight(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestActionTimingsRemoveMember(t *testing.T) {
|
||||
at1 := &ActionTiming{
|
||||
func TestActionPlansRemoveMember(t *testing.T) {
|
||||
at1 := &ActionPlan{
|
||||
Uuid: "some uuid",
|
||||
Id: "test",
|
||||
AccountIds: []string{"one", "two", "three"},
|
||||
ActionsId: "TEST_ACTIONS",
|
||||
}
|
||||
at2 := &ActionTiming{
|
||||
at2 := &ActionPlan{
|
||||
Uuid: "some uuid22",
|
||||
Id: "test2",
|
||||
AccountIds: []string{"three", "four"},
|
||||
ActionsId: "TEST_ACTIONS2",
|
||||
}
|
||||
ats := ActionPlan{at1, at2}
|
||||
if outAts := RemActionTiming(ats, "", "four"); len(outAts[1].AccountIds) != 1 {
|
||||
ats := ActionPlans{at1, at2}
|
||||
if outAts := RemActionPlan(ats, "", "four"); len(outAts[1].AccountIds) != 1 {
|
||||
t.Error("Expecting fewer balance ids", outAts[1].AccountIds)
|
||||
}
|
||||
if ats = RemActionTiming(ats, "", "three"); len(ats) != 1 {
|
||||
if ats = RemActionPlan(ats, "", "three"); len(ats) != 1 {
|
||||
t.Error("Expecting fewer actionTimings", ats)
|
||||
}
|
||||
if ats = RemActionTiming(ats, "some_uuid22", ""); len(ats) != 1 {
|
||||
if ats = RemActionPlan(ats, "some_uuid22", ""); len(ats) != 1 {
|
||||
t.Error("Expecting fewer actionTimings members", ats)
|
||||
}
|
||||
ats2 := ActionPlan{at1, at2}
|
||||
if ats2 = RemActionTiming(ats2, "", ""); len(ats2) != 0 {
|
||||
ats2 := ActionPlans{at1, at2}
|
||||
if ats2 = RemActionPlan(ats2, "", ""); len(ats2) != 0 {
|
||||
t.Error("Should have no members anymore", ats2)
|
||||
}
|
||||
}
|
||||
@@ -995,7 +995,7 @@ func TestActionTriggerLogging(t *testing.T) {
|
||||
storageLogger.LogActionTrigger("rif", RATER_SOURCE, at, as)
|
||||
//expected := "rif*some_uuid;MONETARY;OUT;NAT;TEST_ACTIONS;100;10;false*|TOPUP|MONETARY|OUT|10|0"
|
||||
var key string
|
||||
atMap, _ := accountingStorage.GetAllActionTimings()
|
||||
atMap, _ := accountingStorage.GetAllActionPlans()
|
||||
for k, v := range atMap {
|
||||
_ = k
|
||||
_ = v
|
||||
@@ -1009,7 +1009,7 @@ func TestActionTriggerLogging(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestActionTimingLogging(t *testing.T) {
|
||||
func TestActionPlanLogging(t *testing.T) {
|
||||
i := &RateInterval{
|
||||
Timing: &RITiming{
|
||||
Months: utils.Months{time.January, time.February, time.March, time.April, time.May, time.June, time.July, time.August, time.September, time.October, time.November, time.December},
|
||||
@@ -1024,7 +1024,7 @@ func TestActionTimingLogging(t *testing.T) {
|
||||
Rates: RateGroups{&Rate{0, 1.0, 1 * time.Second, 60 * time.Second}},
|
||||
},
|
||||
}
|
||||
at := &ActionTiming{
|
||||
at := &ActionPlan{
|
||||
Uuid: "some uuid",
|
||||
Id: "test",
|
||||
AccountIds: []string{"one", "two", "three"},
|
||||
@@ -1036,10 +1036,10 @@ func TestActionTimingLogging(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Error("Error getting actions for the action trigger: ", err)
|
||||
}
|
||||
storageLogger.LogActionTiming(SCHED_SOURCE, at, as)
|
||||
storageLogger.LogActionPlan(SCHED_SOURCE, at, as)
|
||||
//expected := "some uuid|test|one,two,three|;1,2,3,4,5,6,7,8,9,10,11,12;1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31;1,2,3,4,5;18:00:00;00:00:00;10;0;1;60;1|10|TEST_ACTIONS*|TOPUP|MONETARY|OUT|10|0"
|
||||
var key string
|
||||
atMap, _ := accountingStorage.GetAllActionTimings()
|
||||
atMap, _ := accountingStorage.GetAllActionPlans()
|
||||
for k, v := range atMap {
|
||||
_ = k
|
||||
_ = v
|
||||
@@ -1073,7 +1073,7 @@ func TestTopupAction(t *testing.T) {
|
||||
Balance: &Balance{Value: 25, DestinationIds: "RET", Weight: 20},
|
||||
}
|
||||
|
||||
at := &ActionTiming{
|
||||
at := &ActionPlan{
|
||||
AccountIds: []string{"*out:vdf:minu"},
|
||||
actions: Actions{a},
|
||||
}
|
||||
@@ -1096,7 +1096,7 @@ func TestTopupActionLoaded(t *testing.T) {
|
||||
Balance: &Balance{Value: 25, DestinationIds: "RET", Weight: 20},
|
||||
}
|
||||
|
||||
at := &ActionTiming{
|
||||
at := &ActionPlan{
|
||||
AccountIds: []string{"*out:vdf:minitsboy"},
|
||||
actions: Actions{a},
|
||||
}
|
||||
|
||||
@@ -466,7 +466,7 @@ func TestMaxSessionTimeWithAccount(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestMaxSessionTimeWithMaxRate(t *testing.T) {
|
||||
ap, _ := accountingStorage.GetActionTimings("TOPUP10_AT")
|
||||
ap, _ := accountingStorage.GetActionPlans("TOPUP10_AT")
|
||||
for _, at := range ap {
|
||||
at.Execute()
|
||||
}
|
||||
@@ -490,7 +490,7 @@ func TestMaxSessionTimeWithMaxRate(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestMaxSessionTimeWithMaxCost(t *testing.T) {
|
||||
ap, _ := accountingStorage.GetActionTimings("TOPUP10_AT")
|
||||
ap, _ := accountingStorage.GetActionPlans("TOPUP10_AT")
|
||||
for _, at := range ap {
|
||||
at.Execute()
|
||||
}
|
||||
@@ -513,7 +513,7 @@ func TestMaxSessionTimeWithMaxCost(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestGetCostWithMaxCost(t *testing.T) {
|
||||
ap, _ := accountingStorage.GetActionTimings("TOPUP10_AT")
|
||||
ap, _ := accountingStorage.GetActionPlans("TOPUP10_AT")
|
||||
for _, at := range ap {
|
||||
at.Execute()
|
||||
}
|
||||
@@ -536,7 +536,7 @@ func TestGetCostWithMaxCost(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestMaxSessionTimeWithMaxCostFree(t *testing.T) {
|
||||
ap, _ := accountingStorage.GetActionTimings("TOPUP10_AT")
|
||||
ap, _ := accountingStorage.GetActionPlans("TOPUP10_AT")
|
||||
for _, at := range ap {
|
||||
at.Execute()
|
||||
}
|
||||
@@ -559,7 +559,7 @@ func TestMaxSessionTimeWithMaxCostFree(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestMaxDebitWithMaxCostFree(t *testing.T) {
|
||||
ap, _ := accountingStorage.GetActionTimings("TOPUP10_AT")
|
||||
ap, _ := accountingStorage.GetActionPlans("TOPUP10_AT")
|
||||
for _, at := range ap {
|
||||
at.Execute()
|
||||
}
|
||||
@@ -582,7 +582,7 @@ func TestMaxDebitWithMaxCostFree(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestGetCostWithMaxCostFree(t *testing.T) {
|
||||
ap, _ := accountingStorage.GetActionTimings("TOPUP10_AT")
|
||||
ap, _ := accountingStorage.GetActionPlans("TOPUP10_AT")
|
||||
for _, at := range ap {
|
||||
at.Execute()
|
||||
}
|
||||
@@ -624,11 +624,11 @@ func TestMaxSessionTimeWithAccountAlias(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestMaxSessionTimeWithAccountShared(t *testing.T) {
|
||||
ap, _ := accountingStorage.GetActionTimings("TOPUP_SHARED0_AT")
|
||||
ap, _ := accountingStorage.GetActionPlans("TOPUP_SHARED0_AT")
|
||||
for _, at := range ap {
|
||||
at.Execute()
|
||||
}
|
||||
ap, _ = accountingStorage.GetActionTimings("TOPUP_SHARED10_AT")
|
||||
ap, _ = accountingStorage.GetActionPlans("TOPUP_SHARED10_AT")
|
||||
for _, at := range ap {
|
||||
at.Execute()
|
||||
}
|
||||
@@ -663,11 +663,11 @@ func TestMaxSessionTimeWithAccountShared(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestMaxDebitWithAccountShared(t *testing.T) {
|
||||
ap, _ := accountingStorage.GetActionTimings("TOPUP_SHARED0_AT")
|
||||
ap, _ := accountingStorage.GetActionPlans("TOPUP_SHARED0_AT")
|
||||
for _, at := range ap {
|
||||
at.Execute()
|
||||
}
|
||||
ap, _ = accountingStorage.GetActionTimings("TOPUP_SHARED10_AT")
|
||||
ap, _ = accountingStorage.GetActionPlans("TOPUP_SHARED10_AT")
|
||||
for _, at := range ap {
|
||||
at.Execute()
|
||||
}
|
||||
@@ -849,7 +849,7 @@ func TestMaxSesionTimeEmptyBalanceAndNoCost(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestDebitFromShareAndNormal(t *testing.T) {
|
||||
ap, _ := accountingStorage.GetActionTimings("TOPUP_SHARED10_AT")
|
||||
ap, _ := accountingStorage.GetActionPlans("TOPUP_SHARED10_AT")
|
||||
for _, at := range ap {
|
||||
at.Execute()
|
||||
}
|
||||
@@ -877,7 +877,7 @@ func TestDebitFromShareAndNormal(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestDebitFromEmptyShare(t *testing.T) {
|
||||
ap, _ := accountingStorage.GetActionTimings("TOPUP_EMPTY_AT")
|
||||
ap, _ := accountingStorage.GetActionPlans("TOPUP_EMPTY_AT")
|
||||
for _, at := range ap {
|
||||
at.Execute()
|
||||
}
|
||||
@@ -905,7 +905,7 @@ func TestDebitFromEmptyShare(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestMaxDebitZeroDefinedRate(t *testing.T) {
|
||||
ap, _ := accountingStorage.GetActionTimings("TOPUP10_AT")
|
||||
ap, _ := accountingStorage.GetActionPlans("TOPUP10_AT")
|
||||
for _, at := range ap {
|
||||
at.Execute()
|
||||
}
|
||||
@@ -933,7 +933,7 @@ func TestMaxDebitZeroDefinedRate(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestMaxDebitZeroDefinedRateOnlyMinutes(t *testing.T) {
|
||||
ap, _ := accountingStorage.GetActionTimings("TOPUP10_AT")
|
||||
ap, _ := accountingStorage.GetActionPlans("TOPUP10_AT")
|
||||
for _, at := range ap {
|
||||
at.Execute()
|
||||
}
|
||||
@@ -961,7 +961,7 @@ func TestMaxDebitZeroDefinedRateOnlyMinutes(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestMaxDebitConsumesMinutes(t *testing.T) {
|
||||
ap, _ := accountingStorage.GetActionTimings("TOPUP10_AT")
|
||||
ap, _ := accountingStorage.GetActionPlans("TOPUP10_AT")
|
||||
for _, at := range ap {
|
||||
at.Execute()
|
||||
}
|
||||
|
||||
@@ -213,43 +213,43 @@ func init() {
|
||||
csvr = NewTpReader(dataStorage, accountingStorage, NewStringCSVStorage(',', destinations, timings, rates, destinationRates, ratingPlans, ratingProfiles,
|
||||
sharedGroups, lcrs, actions, actionTimings, actionTriggers, accountActions, derivedCharges, cdrStats), "")
|
||||
if err := csvr.LoadDestinations(); err != nil {
|
||||
log.Print("error in LoadCdrStats:", err)
|
||||
log.Print("error in LoadDestinations:", err)
|
||||
}
|
||||
if err := csvr.LoadTimings(); err != nil {
|
||||
log.Print("error in LoadCdrStats:", err)
|
||||
log.Print("error in LoadTimings:", err)
|
||||
}
|
||||
if err := csvr.LoadRates(); err != nil {
|
||||
log.Print("error in LoadCdrStats:", err)
|
||||
log.Print("error in LoadRates:", err)
|
||||
}
|
||||
if err := csvr.LoadDestinationRates(); err != nil {
|
||||
log.Print("error in LoadCdrStats:", err)
|
||||
log.Print("error in LoadDestRates:", err)
|
||||
}
|
||||
if err := csvr.LoadRatingPlans(); err != nil {
|
||||
log.Print("error in LoadCdrStats:", err)
|
||||
log.Print("error in LoadRatingPlans:", err)
|
||||
}
|
||||
if err := csvr.LoadRatingProfiles(); err != nil {
|
||||
log.Print("error in LoadCdrStats:", err)
|
||||
log.Print("error in LoadRatingProfiles:", err)
|
||||
}
|
||||
if err := csvr.LoadSharedGroups(); err != nil {
|
||||
log.Print("error in LoadCdrStats:", err)
|
||||
log.Print("error in LoadSharedGroups:", err)
|
||||
}
|
||||
if err := csvr.LoadLCRs(); err != nil {
|
||||
log.Print("error in LoadCdrStats:", err)
|
||||
log.Print("error in LoadLCR:", err)
|
||||
}
|
||||
if err := csvr.LoadActions(); err != nil {
|
||||
log.Print("error in LoadCdrStats:", err)
|
||||
log.Print("error in LoadActions:", err)
|
||||
}
|
||||
if err := csvr.LoadActionPlans(); err != nil {
|
||||
log.Print("error in LoadCdrStats:", err)
|
||||
log.Print("error in LoadActionPlans:", err)
|
||||
}
|
||||
if err := csvr.LoadActionTriggers(); err != nil {
|
||||
log.Print("error in LoadCdrStats:", err)
|
||||
log.Print("error in LoadActionTriggers:", err)
|
||||
}
|
||||
if err := csvr.LoadAccountActions(); err != nil {
|
||||
log.Print("error in LoadCdrStats:", err)
|
||||
log.Print("error in LoadAccountActions:", err)
|
||||
}
|
||||
if err := csvr.LoadDerivedChargers(); err != nil {
|
||||
log.Print("error in LoadCdrStats:", err)
|
||||
log.Print("error in LoadDerivedChargers:", err)
|
||||
}
|
||||
if err := csvr.LoadCdrStats(); err != nil {
|
||||
log.Print("error in LoadCdrStats:", err)
|
||||
@@ -907,7 +907,7 @@ func TestLoadActionTimings(t *testing.T) {
|
||||
t.Error("Failed to load action timings: ", csvr.actionsTimings)
|
||||
}
|
||||
atm := csvr.actionsTimings["MORE_MINUTES"][0]
|
||||
expected := &ActionTiming{
|
||||
expected := &ActionPlan{
|
||||
Uuid: atm.Uuid,
|
||||
Id: "MORE_MINUTES",
|
||||
AccountIds: []string{"*out:vdf:minitsboy"},
|
||||
@@ -1024,7 +1024,8 @@ func TestLoadDerivedChargers(t *testing.T) {
|
||||
DisconnectCauseField: utils.META_DEFAULT},
|
||||
}
|
||||
keyCharger1 := utils.DerivedChargersKey("*out", "cgrates.org", "call", "dan", "dan")
|
||||
if !reflect.DeepEqual(csvr.derivedChargers[keyCharger1], expCharger1) {
|
||||
|
||||
if !csvr.derivedChargers[keyCharger1].Equal(expCharger1) {
|
||||
t.Errorf("Unexpected charger %+v", csvr.derivedChargers[keyCharger1][0])
|
||||
}
|
||||
}
|
||||
@@ -1062,6 +1063,6 @@ func TestLoadCdrStats(t *testing.T) {
|
||||
cdrStats1.Triggers = append(cdrStats1.Triggers, csvr.actionsTriggers["STANDARD_TRIGGERS"]...)
|
||||
cdrStats1.Triggers = append(cdrStats1.Triggers, csvr.actionsTriggers["STANDARD_TRIGGER"]...)
|
||||
if !reflect.DeepEqual(csvr.cdrStats[cdrStats1.Id], cdrStats1) {
|
||||
t.Error("Unexpected stats", csvr.cdrStats[cdrStats1.Id])
|
||||
t.Errorf("Unexpected stats %+v", csvr.cdrStats[cdrStats1.Id])
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,8 +34,8 @@ func csvLoad(s interface{}, values []string) (interface{}, error) {
|
||||
}
|
||||
}
|
||||
elem := reflect.New(st).Elem()
|
||||
for fildName, fieldValue := range fieldValueMap {
|
||||
field := elem.FieldByName(fildName)
|
||||
for fieldName, fieldValue := range fieldValueMap {
|
||||
field := elem.FieldByName(fieldName)
|
||||
if field.IsValid() {
|
||||
switch field.Kind() {
|
||||
case reflect.Float64:
|
||||
@@ -44,7 +44,7 @@ func csvLoad(s interface{}, values []string) (interface{}, error) {
|
||||
}
|
||||
value, err := strconv.ParseFloat(fieldValue, 64)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf(`invalid value "%s" for field %s.%s`, fieldValue, st.Name(), fildName)
|
||||
return nil, fmt.Errorf(`invalid value "%s" for field %s.%s`, fieldValue, st.Name(), fieldName)
|
||||
}
|
||||
field.SetFloat(value)
|
||||
case reflect.Int:
|
||||
@@ -53,9 +53,18 @@ func csvLoad(s interface{}, values []string) (interface{}, error) {
|
||||
}
|
||||
value, err := strconv.Atoi(fieldValue)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf(`invalid value "%s" for field %s.%s`, fieldValue, st.Name(), fildName)
|
||||
return nil, fmt.Errorf(`invalid value "%s" for field %s.%s`, fieldValue, st.Name(), fieldName)
|
||||
}
|
||||
field.SetInt(int64(value))
|
||||
case reflect.Bool:
|
||||
if fieldValue == "" {
|
||||
fieldValue = "false"
|
||||
}
|
||||
value, err := strconv.ParseBool(fieldValue)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf(`invalid value "%s" for field %s.%s`, fieldValue, st.Name(), fieldName)
|
||||
}
|
||||
field.SetBool(value)
|
||||
case reflect.String:
|
||||
field.SetString(fieldValue)
|
||||
}
|
||||
@@ -392,22 +401,23 @@ func (tps TpDerivedChargers) GetDerivedChargers() (map[string]*utils.TPDerivedCh
|
||||
if _, hasIt := dcs[tag]; !hasIt {
|
||||
dcs[tag] = tpDc
|
||||
}
|
||||
dcs[tag].DerivedChargers = append(dcs[tag].DerivedChargers, &utils.TPDerivedCharger{
|
||||
RunId: tpDcMdl.Runid,
|
||||
nDc := &utils.TPDerivedCharger{
|
||||
RunId: ValueOrDefault(tpDcMdl.Runid, utils.META_DEFAULT),
|
||||
RunFilters: tpDcMdl.RunFilters,
|
||||
ReqTypeField: tpDcMdl.ReqTypeField,
|
||||
DirectionField: tpDcMdl.DirectionField,
|
||||
TenantField: tpDcMdl.TenantField,
|
||||
CategoryField: tpDcMdl.CategoryField,
|
||||
AccountField: tpDcMdl.AccountField,
|
||||
SubjectField: tpDcMdl.SubjectField,
|
||||
DestinationField: tpDcMdl.DestinationField,
|
||||
SetupTimeField: tpDcMdl.SetupTimeField,
|
||||
AnswerTimeField: tpDcMdl.AnswerTimeField,
|
||||
UsageField: tpDcMdl.UsageField,
|
||||
SupplierField: tpDcMdl.SupplierField,
|
||||
DisconnectCauseField: tpDcMdl.DisconnectCauseField,
|
||||
})
|
||||
ReqTypeField: ValueOrDefault(tpDcMdl.ReqTypeField, utils.META_DEFAULT),
|
||||
DirectionField: ValueOrDefault(tpDcMdl.DirectionField, utils.META_DEFAULT),
|
||||
TenantField: ValueOrDefault(tpDcMdl.TenantField, utils.META_DEFAULT),
|
||||
CategoryField: ValueOrDefault(tpDcMdl.CategoryField, utils.META_DEFAULT),
|
||||
AccountField: ValueOrDefault(tpDcMdl.AccountField, utils.META_DEFAULT),
|
||||
SubjectField: ValueOrDefault(tpDcMdl.SubjectField, utils.META_DEFAULT),
|
||||
DestinationField: ValueOrDefault(tpDcMdl.DestinationField, utils.META_DEFAULT),
|
||||
SetupTimeField: ValueOrDefault(tpDcMdl.SetupTimeField, utils.META_DEFAULT),
|
||||
AnswerTimeField: ValueOrDefault(tpDcMdl.AnswerTimeField, utils.META_DEFAULT),
|
||||
UsageField: ValueOrDefault(tpDcMdl.UsageField, utils.META_DEFAULT),
|
||||
SupplierField: ValueOrDefault(tpDcMdl.SupplierField, utils.META_DEFAULT),
|
||||
DisconnectCauseField: ValueOrDefault(tpDcMdl.DisconnectCauseField, utils.META_DEFAULT),
|
||||
}
|
||||
dcs[tag].DerivedChargers = append(dcs[tag].DerivedChargers, nDc)
|
||||
}
|
||||
return dcs, nil
|
||||
}
|
||||
@@ -446,7 +456,7 @@ func (tps TpCdrStats) GetCdrStats() (map[string][]*utils.TPCdrStat, error) {
|
||||
}
|
||||
|
||||
func UpdateCdrStats(cs *CdrStats, triggers ActionTriggerPriotityList, tpCs *utils.TPCdrStat) {
|
||||
if tpCs.QueueLength != "" {
|
||||
if tpCs.QueueLength != "" && tpCs.QueueLength != "0" {
|
||||
if qi, err := strconv.Atoi(tpCs.QueueLength); err == nil {
|
||||
cs.QueueLength = qi
|
||||
} else {
|
||||
@@ -587,3 +597,11 @@ func UpdateCdrStats(cs *CdrStats, triggers ActionTriggerPriotityList, tpCs *util
|
||||
cs.Triggers = append(cs.Triggers, triggers...)
|
||||
}
|
||||
}
|
||||
|
||||
// ValueOrDefault is used to populate empty values with *any or *default if value missing
|
||||
func ValueOrDefault(val string, deflt string) string {
|
||||
if len(val) == 0 {
|
||||
val = deflt
|
||||
}
|
||||
return val
|
||||
}
|
||||
|
||||
@@ -10,8 +10,16 @@ func TestModelHelperCsvLoad(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestModelHelperCsvLoadInt(t *testing.T) {
|
||||
l, err := csvLoad(TpCdrStat{}, []string{"CDRST1", "5", "60m", "ASR", "2014-07-29T15:00:00Z;2014-07-29T16:00:00Z", "*voice", "87.139.12.167", "FS_JSON", "*rated", "*out", "cgrates.org", "call", "dan", "dan", "49", "5m;10m", "suppl1", "NORMAL_CLEARING", "default", "rif", "rif", "0;2", "STANDARD_TRIGGERS"})
|
||||
tpd := l.(TpCdrStat)
|
||||
if err != nil || tpd.QueueLength != 5 {
|
||||
t.Errorf("model load failed: %+v", tpd)
|
||||
}
|
||||
}
|
||||
|
||||
func TestModelHelperCsvDump(t *testing.T) {
|
||||
tpd := &TpDestination{
|
||||
tpd := TpDestination{
|
||||
Tag: "TEST_DEST",
|
||||
Prefix: "+492"}
|
||||
csv, err := csvDump(tpd)
|
||||
|
||||
@@ -193,13 +193,13 @@ type TpActionTrigger struct {
|
||||
BalanceTag string `index:"6" re:""`
|
||||
BalanceType string `index:"7" re:""`
|
||||
BalanceDirection string `index:"8" re:""`
|
||||
BalanceDestinationTags string `index:"9" re:""`
|
||||
BalanceWeight float64 `index:"10" re:""`
|
||||
BalanceExpiryTime string `index:"11" re:""`
|
||||
BalanceTimingTags string `index:"12" re:""`
|
||||
BalanceRatingSubject string `index:"13" re:""`
|
||||
BalanceCategory string `index:"14" re:""`
|
||||
BalanceSharedGroup string `index:"15" re:""`
|
||||
BalanceCategory string `index:"9" re:""`
|
||||
BalanceDestinationTags string `index:"10" re:""`
|
||||
BalanceRatingSubject string `index:"11" re:""`
|
||||
BalanceSharedGroup string `index:"12" re:""`
|
||||
BalanceExpiryTime string `index:"13" re:""`
|
||||
BalanceTimingTags string `index:"14" re:""`
|
||||
BalanceWeight float64 `index:"15" re:""`
|
||||
MinQueuedItems int `index:"16" re:""`
|
||||
ActionsTag string `index:"17" re:""`
|
||||
Weight float64 `index:"18" re:""`
|
||||
@@ -210,9 +210,9 @@ type TpAccountAction struct {
|
||||
Id int64
|
||||
Tpid string
|
||||
Loadid string
|
||||
Direction string `index:"0" re:""`
|
||||
Tenant string `index:"1" re:""`
|
||||
Account string `index:"2" re:""`
|
||||
Tenant string `index:"0" re:""`
|
||||
Account string `index:"1" re:""`
|
||||
Direction string `index:"2" re:""`
|
||||
ActionPlanTag string `index:"3" re:""`
|
||||
ActionTriggersTag string `index:"4" re:""`
|
||||
CreatedAt time.Time
|
||||
|
||||
@@ -79,6 +79,7 @@ func (csvs *CSVStorage) GetTpTimings(string, string) ([]TpTiming, error) {
|
||||
return nil, err
|
||||
}
|
||||
if tpTiming, err := csvLoad(TpTiming{}, record); err != nil {
|
||||
log.Print("error loading timing: ", err)
|
||||
return nil, err
|
||||
} else {
|
||||
tpTimings = append(tpTimings, tpTiming.(TpTiming))
|
||||
@@ -104,6 +105,7 @@ func (csvs *CSVStorage) GetTpDestinations(tpid, tag string) ([]TpDestination, er
|
||||
return nil, err
|
||||
}
|
||||
if tpDest, err := csvLoad(TpDestination{}, record); err != nil {
|
||||
log.Print("error loading destination: ", err)
|
||||
return nil, err
|
||||
} else {
|
||||
tpDests = append(tpDests, tpDest.(TpDestination))
|
||||
@@ -129,6 +131,7 @@ func (csvs *CSVStorage) GetTpRates(tpid, tag string) ([]TpRate, error) {
|
||||
return nil, err
|
||||
}
|
||||
if tpRate, err := csvLoad(TpRate{}, record); err != nil {
|
||||
log.Print("error loading rate: ", err)
|
||||
return nil, err
|
||||
} else {
|
||||
tpRates = append(tpRates, tpRate.(TpRate))
|
||||
@@ -154,6 +157,7 @@ func (csvs *CSVStorage) GetTpDestinationRates(tpid, tag string, p *utils.Paginat
|
||||
return nil, err
|
||||
}
|
||||
if tpRate, err := csvLoad(TpDestinationRate{}, record); err != nil {
|
||||
log.Print("error loading destination rate: ", err)
|
||||
return nil, err
|
||||
} else {
|
||||
tpDestinationRates = append(tpDestinationRates, tpRate.(TpDestinationRate))
|
||||
@@ -179,6 +183,7 @@ func (csvs *CSVStorage) GetTpRatingPlans(tpid, tag string, p *utils.Paginator) (
|
||||
return nil, err
|
||||
}
|
||||
if tpRate, err := csvLoad(TpRatingPlan{}, record); err != nil {
|
||||
log.Print("error loading rating plan: ", err)
|
||||
return nil, err
|
||||
} else {
|
||||
tpRatingPlans = append(tpRatingPlans, tpRate.(TpRatingPlan))
|
||||
@@ -204,6 +209,7 @@ func (csvs *CSVStorage) GetTpRatingProfiles(filter *TpRatingProfile) ([]TpRating
|
||||
return nil, err
|
||||
}
|
||||
if tpRate, err := csvLoad(TpRatingProfile{}, record); err != nil {
|
||||
log.Print("error loading rating profile: ", err)
|
||||
return nil, err
|
||||
} else {
|
||||
tpRatingProfiles = append(tpRatingProfiles, tpRate.(TpRatingProfile))
|
||||
@@ -230,6 +236,7 @@ func (csvs *CSVStorage) GetTpSharedGroups(tpid, tag string) ([]TpSharedGroup, er
|
||||
return nil, err
|
||||
}
|
||||
if tpRate, err := csvLoad(TpSharedGroup{}, record); err != nil {
|
||||
log.Print("error loading shared group: ", err)
|
||||
return nil, err
|
||||
} else {
|
||||
tpSharedGroups = append(tpSharedGroups, tpRate.(TpSharedGroup))
|
||||
@@ -302,6 +309,7 @@ func (csvs *CSVStorage) GetTpActionPlans(tpid, tag string) ([]TpActionPlan, erro
|
||||
var tpActionPlans []TpActionPlan
|
||||
for record, err := csvReader.Read(); err != io.EOF; record, err = csvReader.Read() {
|
||||
if tpRate, err := csvLoad(TpActionPlan{}, record); err != nil {
|
||||
log.Print("error loading action plan: ", err)
|
||||
return nil, err
|
||||
} else {
|
||||
tpActionPlans = append(tpActionPlans, tpRate.(TpActionPlan))
|
||||
@@ -327,6 +335,7 @@ func (csvs *CSVStorage) GetTpActionTriggers(tpid, tag string) ([]TpActionTrigger
|
||||
return nil, err
|
||||
}
|
||||
if tpAt, err := csvLoad(TpActionTrigger{}, record); err != nil {
|
||||
log.Print("error loading action trigger: ", err)
|
||||
return nil, err
|
||||
} else {
|
||||
tpActionTriggers = append(tpActionTriggers, tpAt.(TpActionTrigger))
|
||||
@@ -351,10 +360,11 @@ func (csvs *CSVStorage) GetTpAccountActions(filter *TpAccountAction) ([]TpAccoun
|
||||
log.Print("bad line in account actions csv: ", err)
|
||||
return nil, err
|
||||
}
|
||||
if tpRate, err := csvLoad(TpAccountAction{}, record); err != nil {
|
||||
if tpAa, err := csvLoad(TpAccountAction{}, record); err != nil {
|
||||
log.Print("error loading account action: ", err)
|
||||
return nil, err
|
||||
} else {
|
||||
tpAccountActions = append(tpAccountActions, tpRate.(TpAccountAction))
|
||||
tpAccountActions = append(tpAccountActions, tpAa.(TpAccountAction))
|
||||
}
|
||||
}
|
||||
return tpAccountActions, nil
|
||||
@@ -377,6 +387,7 @@ func (csvs *CSVStorage) GetTpDerivedChargers(filter *TpDerivedCharger) ([]TpDeri
|
||||
return nil, err
|
||||
}
|
||||
if tpRate, err := csvLoad(TpDerivedCharger{}, record); err != nil {
|
||||
log.Print("error loading derived charger: ", err)
|
||||
return nil, err
|
||||
} else {
|
||||
tpDerivedChargers = append(tpDerivedChargers, tpRate.(TpDerivedCharger))
|
||||
@@ -402,6 +413,7 @@ func (csvs *CSVStorage) GetTpCdrStats(tpid, tag string) ([]TpCdrStat, error) {
|
||||
return nil, err
|
||||
}
|
||||
if tpCdrStat, err := csvLoad(TpCdrStat{}, record); err != nil {
|
||||
log.Print("error loading cdr stat: ", err)
|
||||
return nil, err
|
||||
} else {
|
||||
tpCdrStats = append(tpCdrStats, tpCdrStat.(TpCdrStat))
|
||||
|
||||
@@ -103,9 +103,9 @@ type AccountingStorage interface {
|
||||
SetAccAlias(string, string) error
|
||||
RemoveAccAliases([]*TenantAccount) error
|
||||
GetAccountAliases(string, string, bool) ([]string, error)
|
||||
GetActionTimings(string) (ActionPlans, error)
|
||||
SetActionTimings(string, ActionPlans) error
|
||||
GetAllActionTimings() (map[string]ActionPlans, error)
|
||||
GetActionPlans(string) (ActionPlans, error)
|
||||
SetActionPlans(string, ActionPlans) error
|
||||
GetAllActionPlans() (map[string]ActionPlans, error)
|
||||
GetDerivedChargers(string, bool) (utils.DerivedChargers, error)
|
||||
SetDerivedChargers(string, utils.DerivedChargers) error
|
||||
}
|
||||
|
||||
@@ -513,7 +513,7 @@ func (ms *MapStorage) SetAccount(ub *Account) (err error) {
|
||||
return
|
||||
}
|
||||
|
||||
func (ms *MapStorage) GetActionTimings(key string) (ats ActionPlans, err error) {
|
||||
func (ms *MapStorage) GetActionPlans(key string) (ats ActionPlans, err error) {
|
||||
if values, ok := ms.dict[ACTION_TIMING_PREFIX+key]; ok {
|
||||
err = ms.ms.Unmarshal(values, &ats)
|
||||
} else {
|
||||
@@ -522,7 +522,7 @@ func (ms *MapStorage) GetActionTimings(key string) (ats ActionPlans, err error)
|
||||
return
|
||||
}
|
||||
|
||||
func (ms *MapStorage) SetActionTimings(key string, ats ActionPlans) (err error) {
|
||||
func (ms *MapStorage) SetActionPlans(key string, ats ActionPlans) (err error) {
|
||||
if len(ats) == 0 {
|
||||
// delete the key
|
||||
delete(ms.dict, ACTION_TIMING_PREFIX+key)
|
||||
@@ -533,7 +533,7 @@ func (ms *MapStorage) SetActionTimings(key string, ats ActionPlans) (err error)
|
||||
return
|
||||
}
|
||||
|
||||
func (ms *MapStorage) GetAllActionTimings() (ats map[string]ActionPlans, err error) {
|
||||
func (ms *MapStorage) GetAllActionPlans() (ats map[string]ActionPlans, err error) {
|
||||
ats = make(map[string]ActionPlans)
|
||||
for key, value := range ms.dict {
|
||||
if !strings.HasPrefix(key, ACTION_TIMING_PREFIX) {
|
||||
|
||||
@@ -646,7 +646,7 @@ func (rs *RedisStorage) SetAccount(ub *Account) (err error) {
|
||||
return
|
||||
}
|
||||
|
||||
func (rs *RedisStorage) GetActionTimings(key string) (ats ActionPlan, err error) {
|
||||
func (rs *RedisStorage) GetActionPlans(key string) (ats ActionPlans, err error) {
|
||||
var values []byte
|
||||
if values, err = rs.db.Get(ACTION_TIMING_PREFIX + key); err == nil {
|
||||
err = rs.ms.Unmarshal(values, &ats)
|
||||
@@ -654,7 +654,7 @@ func (rs *RedisStorage) GetActionTimings(key string) (ats ActionPlan, err error)
|
||||
return
|
||||
}
|
||||
|
||||
func (rs *RedisStorage) SetActionTimings(key string, ats ActionPlan) (err error) {
|
||||
func (rs *RedisStorage) SetActionPlans(key string, ats ActionPlans) (err error) {
|
||||
if len(ats) == 0 {
|
||||
// delete the key
|
||||
_, err = rs.db.Del(ACTION_TIMING_PREFIX + key)
|
||||
@@ -665,18 +665,18 @@ func (rs *RedisStorage) SetActionTimings(key string, ats ActionPlan) (err error)
|
||||
return
|
||||
}
|
||||
|
||||
func (rs *RedisStorage) GetAllActionTimings() (ats map[string]ActionPlan, err error) {
|
||||
func (rs *RedisStorage) GetAllActionPlans() (ats map[string]ActionPlans, err error) {
|
||||
keys, err := rs.db.Keys(ACTION_TIMING_PREFIX + "*")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
ats = make(map[string]ActionPlan, len(keys))
|
||||
ats = make(map[string]ActionPlans, len(keys))
|
||||
for _, key := range keys {
|
||||
values, err := rs.db.Get(key)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
var tempAts ActionPlan
|
||||
var tempAts ActionPlans
|
||||
err = rs.ms.Unmarshal(values, &tempAts)
|
||||
ats[key[len(ACTION_TIMING_PREFIX):]] = tempAts
|
||||
}
|
||||
|
||||
@@ -1218,8 +1218,8 @@ func (self *SQLStorage) GetTpActionTriggers(tpid, tag string) ([]TpActionTrigger
|
||||
return tpActionTriggers, nil
|
||||
}
|
||||
|
||||
func (self *SQLStorage) GetTpActionPlans(tpid, tag string) ([]*TpActionPlan, error) {
|
||||
var tpActionPlans []*TpActionPlan
|
||||
func (self *SQLStorage) GetTpActionPlans(tpid, tag string) ([]TpActionPlan, error) {
|
||||
var tpActionPlans []TpActionPlan
|
||||
q := self.db.Where("tpid = ?", tpid)
|
||||
if len(tag) != 0 {
|
||||
q = q.Where("tag = ?", tag)
|
||||
|
||||
@@ -764,7 +764,7 @@ func (tpr *TpReader) LoadAccountActions() (err error) {
|
||||
|
||||
for _, aa := range storAts {
|
||||
if _, alreadyDefined := tpr.accountActions[aa.KeyId()]; alreadyDefined {
|
||||
return fmt.Errorf("Duplicate account action found: %s", aa.KeyId())
|
||||
return fmt.Errorf("duplicate account action found: %s", aa.KeyId())
|
||||
}
|
||||
|
||||
// extract aliases from subject
|
||||
@@ -776,9 +776,12 @@ func (tpr *TpReader) LoadAccountActions() (err error) {
|
||||
tpr.accAliases[utils.AccountAliasKey(aa.Tenant, alias)] = aa.Account
|
||||
}
|
||||
}
|
||||
aTriggers, exists := tpr.actionsTriggers[aa.ActionTriggersId]
|
||||
if !exists {
|
||||
return fmt.Errorf("Could not get action triggers for tag %v", aa.ActionTriggersId)
|
||||
var aTriggers []*ActionTrigger
|
||||
if aa.ActionTriggersId != "" {
|
||||
var exists bool
|
||||
if aTriggers, exists = tpr.actionsTriggers[aa.ActionTriggersId]; !exists {
|
||||
return fmt.Errorf("could not get action triggers for tag %s", aa.ActionTriggersId)
|
||||
}
|
||||
}
|
||||
ub := &Account{
|
||||
Id: aa.KeyId(),
|
||||
@@ -787,7 +790,7 @@ func (tpr *TpReader) LoadAccountActions() (err error) {
|
||||
tpr.accountActions[aa.KeyId()] = ub
|
||||
aTimings, exists := tpr.actionsTimings[aa.ActionPlanId]
|
||||
if !exists {
|
||||
log.Printf("Could not get action timing for tag %v", aa.ActionPlanId)
|
||||
log.Printf("could not get action plan for tag %v", aa.ActionPlanId)
|
||||
// must not continue here
|
||||
}
|
||||
for _, at := range aTimings {
|
||||
@@ -812,13 +815,13 @@ func (tpr *TpReader) LoadDerivedChargersFiltered(filter *TpDerivedCharger, save
|
||||
tpr.derivedChargers[tag] = make(utils.DerivedChargers, 0) // Load object map since we use this method also from LoadDerivedChargers
|
||||
}
|
||||
for _, tpDc := range tpDcs.DerivedChargers {
|
||||
if dc, err := utils.NewDerivedCharger(tpDc.RunId, tpDc.RunFilters, tpDc.ReqTypeField, tpDc.DirectionField, tpDc.TenantField, tpDc.CategoryField,
|
||||
dc, err := utils.NewDerivedCharger(tpDc.RunId, tpDc.RunFilters, tpDc.ReqTypeField, tpDc.DirectionField, tpDc.TenantField, tpDc.CategoryField,
|
||||
tpDc.AccountField, tpDc.SubjectField, tpDc.DestinationField, tpDc.SetupTimeField, tpDc.AnswerTimeField, tpDc.UsageField, tpDc.SupplierField,
|
||||
tpDc.DisconnectCauseField); err != nil {
|
||||
tpDc.DisconnectCauseField)
|
||||
if err != nil {
|
||||
return err
|
||||
} else {
|
||||
tpr.derivedChargers[tag] = append(tpr.derivedChargers[tag], dc)
|
||||
}
|
||||
tpr.derivedChargers[tag] = append(tpr.derivedChargers[tag], dc)
|
||||
}
|
||||
}
|
||||
if save {
|
||||
|
||||
Reference in New Issue
Block a user