From aa0da215aea4ff08696b06353d28f35939d8ac17 Mon Sep 17 00:00:00 2001 From: TeoV Date: Tue, 27 Mar 2018 10:01:35 -0400 Subject: [PATCH] New folder (tutorial2) for call test --- apier/v1/apier.go | 2 + data/tariffplans/tutorial/AccountActions.csv | 2 - .../tariffplans/tutorial/DestinationRates.csv | 3 - data/tariffplans/tutorial/Destinations.csv | 3 - data/tariffplans/tutorial/Filters.csv | 7 - data/tariffplans/tutorial/RatingPlans.csv | 7 +- data/tariffplans/tutorial/RatingProfiles.csv | 4 +- data/tariffplans/tutorial/Resources.csv | 1 - data/tariffplans/tutorial/SharedGroups.csv | 2 +- data/tariffplans/tutorial/Stats.csv | 3 +- data/tariffplans/tutorial/Suppliers.csv | 3 - data/tariffplans/tutorial/Thresholds.csv | 3 - data/tariffplans/tutorial2/AccountActions.csv | 3 + data/tariffplans/tutorial2/ActionPlans.csv | 2 + data/tariffplans/tutorial2/Actions.csv | 3 + data/tariffplans/tutorial2/Attributes.csv | 3 + .../tutorial2/DestinationRates.csv | 5 + data/tariffplans/tutorial2/Destinations.csv | 5 + data/tariffplans/tutorial2/Filters.csv | 11 + data/tariffplans/tutorial2/Rates.csv | 9 + data/tariffplans/tutorial2/RatingPlans.csv | 4 + data/tariffplans/tutorial2/RatingProfiles.csv | 3 + data/tariffplans/tutorial2/Resources.csv | 3 + data/tariffplans/tutorial2/Stats.csv | 2 + data/tariffplans/tutorial2/Suppliers.csv | 5 + data/tariffplans/tutorial2/Thresholds.csv | 4 + data/tariffplans/tutorial2/Timings.csv | 2 + .../cgrates/etc/cgrates/cgrates.json | 16 +- general_tests/tut_fs_calls_test.go | 259 +++++++++++------- 29 files changed, 243 insertions(+), 136 deletions(-) mode change 100644 => 100755 data/tariffplans/tutorial/SharedGroups.csv create mode 100644 data/tariffplans/tutorial2/AccountActions.csv create mode 100644 data/tariffplans/tutorial2/ActionPlans.csv create mode 100644 data/tariffplans/tutorial2/Actions.csv create mode 100644 data/tariffplans/tutorial2/Attributes.csv create mode 100644 data/tariffplans/tutorial2/DestinationRates.csv create mode 100644 data/tariffplans/tutorial2/Destinations.csv create mode 100644 data/tariffplans/tutorial2/Filters.csv create mode 100644 data/tariffplans/tutorial2/Rates.csv create mode 100644 data/tariffplans/tutorial2/RatingPlans.csv create mode 100644 data/tariffplans/tutorial2/RatingProfiles.csv create mode 100644 data/tariffplans/tutorial2/Resources.csv create mode 100644 data/tariffplans/tutorial2/Stats.csv create mode 100644 data/tariffplans/tutorial2/Suppliers.csv create mode 100644 data/tariffplans/tutorial2/Thresholds.csv create mode 100644 data/tariffplans/tutorial2/Timings.csv diff --git a/apier/v1/apier.go b/apier/v1/apier.go index 5213096ce..5683a0f4b 100644 --- a/apier/v1/apier.go +++ b/apier/v1/apier.go @@ -1840,10 +1840,12 @@ func (self *ApierV1) LoadTariffPlanFromFolder(attrs utils.AttrLoadTpFromFolder, utils.REVERSE_ALIASES_PREFIX} { loadedIDs, _ := loader.GetLoadedIds(prfx) if err := self.DataManager.CacheDataFromDB(prfx, loadedIDs, true); err != nil { + utils.Logger.Debug(fmt.Sprintf("Error here : %+v", err)) return utils.NewErrServerError(err) } } aps, _ := loader.GetLoadedIds(utils.ACTION_PLAN_PREFIX) + utils.Logger.Debug(fmt.Sprintf("ActionPlanPrefix : %+v", aps)) cstKeys, _ := loader.GetLoadedIds(utils.CDR_STATS_PREFIX) userKeys, _ := loader.GetLoadedIds(utils.USERS_PREFIX) diff --git a/data/tariffplans/tutorial/AccountActions.csv b/data/tariffplans/tutorial/AccountActions.csv index 587940d28..97bcd5f64 100644 --- a/data/tariffplans/tutorial/AccountActions.csv +++ b/data/tariffplans/tutorial/AccountActions.csv @@ -4,5 +4,3 @@ cgrates.org,1002,PACKAGE_10,STANDARD_TRIGGERS,, cgrates.org,1003,PACKAGE_10,STANDARD_TRIGGERS,, cgrates.org,1004,PACKAGE_10,STANDARD_TRIGGERS,, cgrates.org,1007,USE_SHARED_A,STANDARD_TRIGGERS,, -cgrates.org,1011,PACKAGE_1001,STANDARD_TRIGGERS,, -cgrates.org,1012,PACKAGE_10,STANDARD_TRIGGERS,, diff --git a/data/tariffplans/tutorial/DestinationRates.csv b/data/tariffplans/tutorial/DestinationRates.csv index b49ffea38..ee3352fc3 100644 --- a/data/tariffplans/tutorial/DestinationRates.csv +++ b/data/tariffplans/tutorial/DestinationRates.csv @@ -9,6 +9,3 @@ DR_SPECIAL_1002,DST_1002,RT_1CNT,*up,4,0, DR_1007_MAXCOST_DISC,DST_1007,RT_1CNT_PER_SEC,*up,4,0.62,*disconnect DR_1007_MAXCOST_FREE,DST_1007,RT_1CNT_PER_SEC,*up,4,0.62,*free DR_GENERIC,*any,RT_GENERIC_1,*up,4,0, -DR_1005_MAXCOST_DISC,DST_1005,RT_1CNT_PER_SEC,*up,4,0.12,*disconnect -DR_1011_10CNT,DST_1011,RT_10CNT,*up,4,0, -DR_1012_20CNT,DST_1012,RT_20CNT,*up,4,0, diff --git a/data/tariffplans/tutorial/Destinations.csv b/data/tariffplans/tutorial/Destinations.csv index f87e000ee..823d3a72f 100644 --- a/data/tariffplans/tutorial/Destinations.csv +++ b/data/tariffplans/tutorial/Destinations.csv @@ -6,6 +6,3 @@ DST_FS,10 DST_DE_MOBILE,+49151 DST_DE_MOBILE,+49161 DST_DE_MOBILE,+49171 -DST_1005,1005 -DST_1011,1011 -DST_1012,1012 diff --git a/data/tariffplans/tutorial/Filters.csv b/data/tariffplans/tutorial/Filters.csv index 1129aec52..0796bbafd 100644 --- a/data/tariffplans/tutorial/Filters.csv +++ b/data/tariffplans/tutorial/Filters.csv @@ -29,11 +29,4 @@ cgrates.org,FLTR_RES_GR3,*string,Account,3001,2014-07-29T15:00:00Z cgrates.org,FLTR_CDRS,*cdr_stats,,CDRST1:*min_ASR:34;CDRST_1001:*min_ASR:20,2014-07-29T15:00:00Z cgrates.org,FLTR_STS1,*string,Account,1001;1002,2014-07-29T15:00:00Z cgrates.org,FLTR_CDR_UPDATE,*string,EventType,CDR,2014-07-29T15:00:00Z -cgrates.org,FLTR_ACNT_1011_1012,*string,Account,1011;1012,2014-07-29T15:00:00Z -cgrates.org,FLTR_ACNT_1011_1012,*string,RunID,*default, -cgrates.org,FLTR_ACNT_1011,*string,Account,1011,2014-07-29T15:00:00Z -cgrates.org,FLTR_ACNT_1012,*string,Account,1012,2014-07-29T15:00:00Z -cgrates.org,FLTR_2,*string,Account,1011;1012,2014-07-29T15:00:00Z -cgrates.org,FLTR_2,*prefix,Destination,10;20, -cgrates.org,FLTR_2,*rsr,,Subject(~^1.*1$);Destination(1012), diff --git a/data/tariffplans/tutorial/RatingPlans.csv b/data/tariffplans/tutorial/RatingPlans.csv index 9559dea4c..59dc663d7 100644 --- a/data/tariffplans/tutorial/RatingPlans.csv +++ b/data/tariffplans/tutorial/RatingPlans.csv @@ -4,7 +4,6 @@ RP_RETAIL1,DR_FS_10CNT,OFFPEAK_MORNING,10 RP_RETAIL1,DR_FS_10CNT,OFFPEAK_EVENING,10 RP_RETAIL1,DR_FS_10CNT,OFFPEAK_WEEKEND,10 RP_RETAIL1,DR_1007_MAXCOST_DISC,*any,10 -RP_RETAIL1,DR_1005_MAXCOST_DISC,*any,10 RP_RETAIL2,DR_1002_20CNT,PEAK,10 RP_RETAIL2,DR_1003_20CNT,PEAK,10 RP_RETAIL2,DR_FS_40CNT,PEAK,10 @@ -18,9 +17,5 @@ RP_RETAIL2,DR_FS_10CNT,OFFPEAK_MORNING,10 RP_RETAIL2,DR_FS_10CNT,OFFPEAK_EVENING,10 RP_RETAIL2,DR_FS_10CNT,OFFPEAK_WEEKEND,10 RP_RETAIL2,DR_1007_MAXCOST_FREE,*any,10 -RP_RETAIL2,DR_1005_MAXCOST_DISC,*any,10 RP_SPECIAL_1002,DR_SPECIAL_1002,*any,10 -RP_GENERIC,DR_GENERIC,*any,10 -RP_1011,DR_1012_20CNT,*any,10 -RP_1011,DR_FS_10CNT,*any,10 -RP_1012,DR_1011_10CNT,*any,10 \ No newline at end of file +RP_GENERIC,DR_GENERIC,*any,10 \ No newline at end of file diff --git a/data/tariffplans/tutorial/RatingProfiles.csv b/data/tariffplans/tutorial/RatingProfiles.csv index b88e9dbb2..04f768da5 100644 --- a/data/tariffplans/tutorial/RatingProfiles.csv +++ b/data/tariffplans/tutorial/RatingProfiles.csv @@ -8,6 +8,4 @@ *out,cgrates.org,lcr_profile1,suppl2,2014-01-14T00:00:00Z,RP_RETAIL2,,STATS_SUPPL2 *out,cgrates.org,lcr_profile2,suppl1,2014-01-14T00:00:00Z,RP_RETAIL2,,STATS_SUPPL1 *out,cgrates.org,lcr_profile2,suppl2,2014-01-14T00:00:00Z,RP_RETAIL1,,STATS_SUPPL2 -*out,cgrates.org,lcr_profile2,suppl3,2014-01-14T00:00:00Z,RP_SPECIAL_1002,, -*out,cgrates.org,call,1011,2014-01-14T00:00:00Z,RP_1011,, -*out,cgrates.org,call,1012,2014-01-14T00:00:00Z,RP_1012,, \ No newline at end of file +*out,cgrates.org,lcr_profile2,suppl3,2014-01-14T00:00:00Z,RP_SPECIAL_1002,, \ No newline at end of file diff --git a/data/tariffplans/tutorial/Resources.csv b/data/tariffplans/tutorial/Resources.csv index 9a1a7b72c..0f47b20a6 100644 --- a/data/tariffplans/tutorial/Resources.csv +++ b/data/tariffplans/tutorial/Resources.csv @@ -2,4 +2,3 @@ cgrates.org,ResGroup1,FLTR_1,2014-07-29T15:00:00Z,1s,7,,false,false,20, cgrates.org,ResGroup2,FLTR_DST_FS,2014-07-29T15:00:00Z,3600s,8,SPECIAL_1002,false,true,10, cgrates.org,ResGroup3,FLTR_RES_GR3,2014-07-29T15:00:00Z,*unlimited,3,,true,false,20, -cgrates.org,ResGroup4,FLTR_2,2014-07-29T15:00:00Z,1s,7,,false,false,20, diff --git a/data/tariffplans/tutorial/SharedGroups.csv b/data/tariffplans/tutorial/SharedGroups.csv old mode 100644 new mode 100755 index 57971a5f4..612f946f6 --- a/data/tariffplans/tutorial/SharedGroups.csv +++ b/data/tariffplans/tutorial/SharedGroups.csv @@ -1,2 +1,2 @@ -#Id,Account,Strategy,RatingSubject +#Id,Account,Strategy,RatingSubject SHARED_A,*any,*highest, \ No newline at end of file diff --git a/data/tariffplans/tutorial/Stats.csv b/data/tariffplans/tutorial/Stats.csv index cc0913e3f..4cdf2b690 100644 --- a/data/tariffplans/tutorial/Stats.csv +++ b/data/tariffplans/tutorial/Stats.csv @@ -1,4 +1,3 @@ #Tenant[0],Id[1],FilterIDs[2],ActivationInterval[3],QueueLength[4],TTL[5],Metrics[6],MetricParams[7],Blocker[8],Stored[9],Weight[10],MinItems[11],ThresholdIDs[12] cgrates.org,Stats1,FLTR_STS1,2014-07-29T15:00:00Z,100,1s,*asr;*acc;*tcc;*acd;*tcd;*pdd,,true,true,20,2,THRESH1;THRESH2 -cgrates.org,Stats1,FLTR_STS1,2014-07-29T15:00:00Z,100,1s,*sum;*average,Value,true,true,20,2,THRESH1;THRESH2 -cgrates.org,Stats2,FLTR_ACNT_1011_1012,2014-07-29T15:00:00Z,100,1s,*tcc;*tcd,,false,true,30,0, +cgrates.org,Stats1,FLTR_STS1,2014-07-29T15:00:00Z,100,1s,*sum;*average,Value,true,true,20,2,THRESH1;THRESH2 \ No newline at end of file diff --git a/data/tariffplans/tutorial/Suppliers.csv b/data/tariffplans/tutorial/Suppliers.csv index 587c0b63f..835129fac 100644 --- a/data/tariffplans/tutorial/Suppliers.csv +++ b/data/tariffplans/tutorial/Suppliers.csv @@ -6,6 +6,3 @@ cgrates.org,SPL_WEIGHT_1,FLTR_ACNT_1007,,,,supplier3,FLTR_ACNT_dan,,,,,15,,, cgrates.org,SPL_LEASTCOST_1,FLTR_1,2017-11-27T00:00:00Z,*least_cost,,supplier1,,,RP_SPECIAL_1002,,,10,false,,10 cgrates.org,SPL_LEASTCOST_1,,,,,supplier2,,,RP_RETAIL1,,,20,,, cgrates.org,SPL_LEASTCOST_1,,,,,supplier3,,,RP_SPECIAL_1002,,,15,,, -cgrates.org,SPL_LEASTCOST_2,FLTR_2,2017-11-27T00:00:00Z,*least_cost,,supplier1,,,RP_1012,,,10,false,,10 -cgrates.org,SPL_LEASTCOST_2,,,,,supplier2,,,RP_1011,,,20,,, -cgrates.org,SPL_LEASTCOST_2,,,,,supplier3,,,RP_1012,,,15,,, diff --git a/data/tariffplans/tutorial/Thresholds.csv b/data/tariffplans/tutorial/Thresholds.csv index 159a9da52..d82fc7ec1 100644 --- a/data/tariffplans/tutorial/Thresholds.csv +++ b/data/tariffplans/tutorial/Thresholds.csv @@ -6,6 +6,3 @@ cgrates.org,THD_STATS_2,FLTR_STATS_2,2014-07-29T15:00:00Z,true,1,1s,false,10,DIS cgrates.org,THD_STATS_3,FLTR_STATS_3,2014-07-29T15:00:00Z,false,1,1s,false,10,TOPUP_100SMS_DE_MOBILE,false cgrates.org,THD_RES_1,FLTR_RES_1,2014-07-29T15:00:00Z,true,1,1s,false,10,LOG_WARNING,false cgrates.org,THD_CDRS_1,FLTR_ACNT_1007;FLTR_CDR_UPDATE,2014-07-29T15:00:00Z,false,1,1s,false,10,LOG_WARNING,false -cgrates.org,THD_ACNT_1011,FLTR_ACNT_1011,2014-07-29T15:00:00Z,false,1,1s,false,10,LOG_WARNING,false -cgrates.org,THD_ACNT_1012,FLTR_ACNT_1012,2014-07-29T15:00:00Z,true,1,1s,false,10,LOG_WARNING,false - diff --git a/data/tariffplans/tutorial2/AccountActions.csv b/data/tariffplans/tutorial2/AccountActions.csv new file mode 100644 index 000000000..ba2493fb6 --- /dev/null +++ b/data/tariffplans/tutorial2/AccountActions.csv @@ -0,0 +1,3 @@ +#Tenant,Account,ActionPlanId,ActionTriggersId,AllowNegative,Disabled +cgrates.org,1001,PACKAGE_10,,, +cgrates.org,1002,PACKAGE_10,,, diff --git a/data/tariffplans/tutorial2/ActionPlans.csv b/data/tariffplans/tutorial2/ActionPlans.csv new file mode 100644 index 000000000..03eba3fb6 --- /dev/null +++ b/data/tariffplans/tutorial2/ActionPlans.csv @@ -0,0 +1,2 @@ +#Id,ActionsId,TimingId,Weight +PACKAGE_10,TOPUP_RST_10,*asap,10 \ No newline at end of file diff --git a/data/tariffplans/tutorial2/Actions.csv b/data/tariffplans/tutorial2/Actions.csv new file mode 100644 index 000000000..d95702054 --- /dev/null +++ b/data/tariffplans/tutorial2/Actions.csv @@ -0,0 +1,3 @@ +#ActionsId[0],Action[1],ExtraParameters[2],Filter[3],BalanceId[4],BalanceType[5],Directions[6],Categories[7],DestinationIds[8],RatingSubject[9],SharedGroup[10],ExpiryTime[11],TimingIds[12],Units[13],BalanceWeight[14],BalanceBlocker[15],BalanceDisabled[16],Weight[17] +TOPUP_RST_10,*topup_reset,,,,*monetary,*out,,*any,,,*unlimited,,10,10,false,false,10 +LOG_WARNING,*log,,,,,,,,,,,,,,false,false,10 \ No newline at end of file diff --git a/data/tariffplans/tutorial2/Attributes.csv b/data/tariffplans/tutorial2/Attributes.csv new file mode 100644 index 000000000..a4dea7fc8 --- /dev/null +++ b/data/tariffplans/tutorial2/Attributes.csv @@ -0,0 +1,3 @@ +#Tenant,ID,Contexts,FilterIDs,ActivationInterval,FieldName,Initial,Substitute,Append,Weight +cgrates.org,ATTR_1,*sessions;*cdrs,*string:Account:1007,2014-01-14T00:00:00Z,Account,*any,1001,false,10 +cgrates.org,ATTR_1,,,,Subject,*any,1001,true, diff --git a/data/tariffplans/tutorial2/DestinationRates.csv b/data/tariffplans/tutorial2/DestinationRates.csv new file mode 100644 index 000000000..db20d5ded --- /dev/null +++ b/data/tariffplans/tutorial2/DestinationRates.csv @@ -0,0 +1,5 @@ +#Id,DestinationId,RatesTag,RoundingMethod,RoundingDecimals,MaxCost,MaxCostStrategy +DR_1001_10CNT,DST_1001,RT_10CNT,*up,4,0, +DR_1002_20CNT,DST_1002,RT_20CNT,*up,4,0, +DR_1003_MAXCOST_DISC,DST_1003,RT_1CNT_PER_SEC,*up,4,0.12,*disconnect + diff --git a/data/tariffplans/tutorial2/Destinations.csv b/data/tariffplans/tutorial2/Destinations.csv new file mode 100644 index 000000000..4be2f31c8 --- /dev/null +++ b/data/tariffplans/tutorial2/Destinations.csv @@ -0,0 +1,5 @@ +#Id,Prefix +DST_1002,1002 +DST_1001,1001 +DST_FS,10 +DST_1003,1003 \ No newline at end of file diff --git a/data/tariffplans/tutorial2/Filters.csv b/data/tariffplans/tutorial2/Filters.csv new file mode 100644 index 000000000..d21aaf841 --- /dev/null +++ b/data/tariffplans/tutorial2/Filters.csv @@ -0,0 +1,11 @@ +#Tenant[0],ID[1],FilterType[2],FilterFieldName[3],FilterFieldValues[4],ActivationInterval[5] +cgrates.org,FLTR_1,*string,Account,1001;1002,2014-07-29T15:00:00Z +cgrates.org,FLTR_1,*prefix,Destination,10;20, +cgrates.org,FLTR_1,*rsr,,Subject(~^1.*1$);Destination(1002), +cgrates.org,FLTR_DST_FS,*destinations,Destination,DST_FS,2014-07-29T15:00:00Z +cgrates.org,FLTR_RES_GR3,*string,Account,1003,2014-07-29T15:00:00Z +cgrates.org,FLTR_ACNT_1001_1002,*string,Account,1001;1002,2014-07-29T15:00:00Z +cgrates.org,FLTR_ACNT_1001_1002,*string,RunID,*default, +cgrates.org,FLTR_ACNT_1001,*string,Account,1001,2014-07-29T15:00:00Z +cgrates.org,FLTR_ACNT_1002,*string,Account,1002,2014-07-29T15:00:00Z + diff --git a/data/tariffplans/tutorial2/Rates.csv b/data/tariffplans/tutorial2/Rates.csv new file mode 100644 index 000000000..c333bff3e --- /dev/null +++ b/data/tariffplans/tutorial2/Rates.csv @@ -0,0 +1,9 @@ +#Id,ConnectFee,Rate,RateUnit,RateIncrement,GroupIntervalStart +RT_10CNT,0.2,0.1,60s,60s,0s +RT_10CNT,0,0.05,60s,1s,60s +RT_20CNT,0.4,0.2,60s,60s,0s +RT_20CNT,0,0.1,60s,1s,60s +RT_40CNT,0.8,0.4,60s,30s,0s +RT_40CNT,0,0.2,60s,10s,60s +RT_1CNT,0,0.01,60s,60s,0s +RT_1CNT_PER_SEC,0,0.01,1s,1s,0s diff --git a/data/tariffplans/tutorial2/RatingPlans.csv b/data/tariffplans/tutorial2/RatingPlans.csv new file mode 100644 index 000000000..33883eb34 --- /dev/null +++ b/data/tariffplans/tutorial2/RatingPlans.csv @@ -0,0 +1,4 @@ +#Id,DestinationRatesId,TimingTag,Weight +RP_1001,DR_1002_20CNT,ALWAYS,10 +RP_1001,DR_1003_MAXCOST_DISC,ALWAYS,10 +RP_1002,DR_1001_10CNT,ALWAYS,10 \ No newline at end of file diff --git a/data/tariffplans/tutorial2/RatingProfiles.csv b/data/tariffplans/tutorial2/RatingProfiles.csv new file mode 100644 index 000000000..e0a2d22b8 --- /dev/null +++ b/data/tariffplans/tutorial2/RatingProfiles.csv @@ -0,0 +1,3 @@ +#Direction,Tenant,Category,Subject,ActivationTime,RatingPlanId,RatesFallbackSubject,CdrStatQueueIds +*out,cgrates.org,call,1001,2014-01-14T00:00:00Z,RP_1001,, +*out,cgrates.org,call,1002,2014-01-14T00:00:00Z,RP_1002,, diff --git a/data/tariffplans/tutorial2/Resources.csv b/data/tariffplans/tutorial2/Resources.csv new file mode 100644 index 000000000..330752991 --- /dev/null +++ b/data/tariffplans/tutorial2/Resources.csv @@ -0,0 +1,3 @@ +#Tenant[0],Id[1],FilterIDs[2],ActivationInterval[3],TTL[4],Limit[5],AllocationMessage[6],Blocker[7],Stored[8],Weight[9],ThresholdIDs[10] +cgrates.org,ResGroup1,FLTR_1,2014-07-29T15:00:00Z,1s,7,,false,false,20, +cgrates.org,ResGroup2,FLTR_DST_FS,2014-07-29T15:00:00Z,3600s,8,SPECIAL_1003,false,true,10, diff --git a/data/tariffplans/tutorial2/Stats.csv b/data/tariffplans/tutorial2/Stats.csv new file mode 100644 index 000000000..4454ea973 --- /dev/null +++ b/data/tariffplans/tutorial2/Stats.csv @@ -0,0 +1,2 @@ +#Tenant[0],Id[1],FilterIDs[2],ActivationInterval[3],QueueLength[4],TTL[5],Metrics[6],MetricParams[7],Blocker[8],Stored[9],Weight[10],MinItems[11],ThresholdIDs[12] +cgrates.org,Stats2,FLTR_ACNT_1001_1002,2014-07-29T15:00:00Z,100,1s,*tcc;*tcd,,false,true,30,0, diff --git a/data/tariffplans/tutorial2/Suppliers.csv b/data/tariffplans/tutorial2/Suppliers.csv new file mode 100644 index 000000000..bb9884cfd --- /dev/null +++ b/data/tariffplans/tutorial2/Suppliers.csv @@ -0,0 +1,5 @@ +#Tenant,ID,FilterIDs,ActivationInterval,Sorting,SortingParamameters,SupplierID,SupplierFilterIDs,SupplierAccountIDs,SupplierRatingPlanIDs,SupplierResourceIDs,SupplierStatIDs,SupplierWeight,SupplierBlocker,SupplierParameters,Weight +cgrates.org,SPL_LEASTCOST_2,,2017-11-27T00:00:00Z,*weight,,supplier1,,,RP_1001,,,10,,,10 +cgrates.org,SPL_LEASTCOST_1,FLTR_1,2017-11-27T00:00:00Z,*least_cost,,supplier1,,,RP_1002,,,10,false,,10 +cgrates.org,SPL_LEASTCOST_1,,,,,supplier2,,,RP_1001,,,20,,, +cgrates.org,SPL_LEASTCOST_1,,,,,supplier3,,,RP_1002,,,15,,, diff --git a/data/tariffplans/tutorial2/Thresholds.csv b/data/tariffplans/tutorial2/Thresholds.csv new file mode 100644 index 000000000..93e0bb440 --- /dev/null +++ b/data/tariffplans/tutorial2/Thresholds.csv @@ -0,0 +1,4 @@ +#Tenant[0],Id[1],FilterIDs[2],ActivationInterval[3],Recurrent[4],MinHits[5],MinSleep[6],Blocker[7],Weight[8],ActionIDs[9],Async[10] +cgrates.org,THD_ACNT_1001,FLTR_ACNT_1001,2014-07-29T15:00:00Z,false,1,1s,false,10,LOG_WARNING,false +cgrates.org,THD_ACNT_1002,FLTR_ACNT_1002,2014-07-29T15:00:00Z,true,1,1s,false,10,LOG_WARNING,false + diff --git a/data/tariffplans/tutorial2/Timings.csv b/data/tariffplans/tutorial2/Timings.csv new file mode 100644 index 000000000..775f347c0 --- /dev/null +++ b/data/tariffplans/tutorial2/Timings.csv @@ -0,0 +1,2 @@ +#Tag,Years,Months,MonthDays,WeekDays,Time +ALWAYS,*any,*any,*any,*any,00:00:00 \ No newline at end of file diff --git a/data/tutorials/fs_evsock/cgrates/etc/cgrates/cgrates.json b/data/tutorials/fs_evsock/cgrates/etc/cgrates/cgrates.json index 44fa10878..d08afa23e 100644 --- a/data/tutorials/fs_evsock/cgrates/etc/cgrates/cgrates.json +++ b/data/tutorials/fs_evsock/cgrates/etc/cgrates/cgrates.json @@ -6,6 +6,10 @@ // This file contains the default configuration hardcoded into CGRateS. // This is what you get when you load CGRateS with an empty configuration file. +"general": { + "log_level":7, +}, + "listen": { "rpc_json": ":2012", @@ -36,7 +40,7 @@ {"address": "*internal"} ], "attributes_conns": [ - {"address": "*internal"} + {"address": "127.0.0.1:2012", "transport": "*json"} ], }, @@ -62,13 +66,13 @@ {"address": "127.0.0.1:2012", "transport": "*json"} ], "resources_conns": [ - {"address": "*internal"} + {"address": "127.0.0.1:2012", "transport": "*json"} ], "suppliers_conns": [ - {"address": "*internal"} + {"address": "127.0.0.1:2012", "transport": "*json"} ], "attributes_conns": [ - {"address": "*internal"} + {"address": "127.0.0.1:2012", "transport": "*json"} ], "stats_conns": [ {"address": "127.0.0.1:2012", "transport": "*json"} @@ -114,13 +118,13 @@ "thresholds_conns": [ {"address": "*internal"} ], - "string_indexed_fields": ["Account","EventType"], + "string_indexed_fields": ["Account"], }, "thresholds": { "enabled": true, - "string_indexed_fields": ["Account","EventType","StatID","ResourceID"], + "string_indexed_fields": ["Account"], }, diff --git a/general_tests/tut_fs_calls_test.go b/general_tests/tut_fs_calls_test.go index b94bc0f5f..a09ce1885 100755 --- a/general_tests/tut_fs_calls_test.go +++ b/general_tests/tut_fs_calls_test.go @@ -53,20 +53,23 @@ var sTestsCalls = []func(t *testing.T){ testCallRpcConn, testCallLoadTariffPlanFromFolder, testCallAccountsBefore, - testCallStartPjsuaListener, + testCallStatMetricsBefore, testCallCheckResourceBeforeAllocation, testCallCheckThreshold1001Before, testCallCheckThreshold1002Before, + testCallStartPjsuaListener, testCallCall1001To1002, - testCallCall1002To1001, testCallGetActiveSessions, + testCallCall1002To1001, + testCallCall1001To1003, testCallCheckResourceAllocation, testCallAccount1001, + testCall1001Cdrs, + testCall1002Cdrs, + testCallStatMetrics, + testCallCheckResourceRelease, testCallCheckThreshold1001After, testCallCheckThreshold1002After, - testCallCheckResourceRelease, - testCall1001Cdrs, - testCallStatMetrics, testCallStopPjsuaListener, testCallStopCgrEngine, testCallStopFS, @@ -74,7 +77,6 @@ var sTestsCalls = []func(t *testing.T){ //Test start here func TestFSCall(t *testing.T) { - for _, stest := range sTestsCalls { t.Run("", stest) } @@ -140,12 +142,10 @@ func testCallRpcConn(t *testing.T) { // Load the tariff plan, creating accounts and their balances func testCallLoadTariffPlanFromFolder(t *testing.T) { - reply := "" - attrs := &utils.AttrLoadTpFromFolder{FolderPath: path.Join(*dataDir, "tariffplans", "tutorial")} + var reply string + attrs := &utils.AttrLoadTpFromFolder{FolderPath: path.Join(*dataDir, "tariffplans", "tutorial2")} if err := tutFsCallsRpc.Call("ApierV1.LoadTariffPlanFromFolder", attrs, &reply); err != nil { t.Error(err) - } else if reply != "OK" { - t.Error(reply) } time.Sleep(time.Duration(*waitRater) * time.Millisecond) // Give time for scheduler to execute topups } @@ -156,22 +156,29 @@ func testCallAccountsBefore(t *testing.T) { attrs := &utils.AttrGetAccount{Tenant: "cgrates.org", Account: "1001"} if err := tutFsCallsRpc.Call("ApierV2.GetAccount", attrs, &reply); err != nil { t.Error("Got error on ApierV2.GetAccount: ", err.Error()) - } else if reply.BalanceMap[utils.MONETARY].GetTotalValue() != 10.0 { // Make sure we debitted + } else if reply.BalanceMap[utils.MONETARY].GetTotalValue() != 10.0 { t.Errorf("Calling ApierV1.GetBalance received: %f", reply.BalanceMap[utils.MONETARY].GetTotalValue()) } + var reply2 *engine.Account + attrs2 := &utils.AttrGetAccount{Tenant: "cgrates.org", Account: "1002"} + if err := tutFsCallsRpc.Call("ApierV2.GetAccount", attrs2, &reply2); err != nil { + t.Error("Got error on ApierV2.GetAccount: ", err.Error()) + } else if reply2.BalanceMap[utils.MONETARY].GetTotalValue() != 10.0 { + t.Errorf("Calling ApierV1.GetBalance received: %f", reply2.BalanceMap[utils.MONETARY].GetTotalValue()) + } } -// Start Pjsua as listener and register it to receive calls -func testCallStartPjsuaListener(t *testing.T) { - var err error - acnts := []*engine.PjsuaAccount{ - &engine.PjsuaAccount{Id: "sip:1011@192.168.56.202", - Username: "1011", Password: "CGRateS.org", Realm: "*", Registrar: "sip:192.168.56.202:5060"}, - &engine.PjsuaAccount{Id: "sip:1012@192.168.56.202", - Username: "1012", Password: "CGRateS.org", Realm: "*", Registrar: "sip:192.168.56.202:5060"}} - if tutFsCallsPjSuaListener, err = engine.StartPjsuaListener( - acnts, 5070, time.Duration(*waitRater)*time.Millisecond); err != nil { - t.Fatal(err) +func testCallStatMetricsBefore(t *testing.T) { + var metrics map[string]string + expectedMetrics := map[string]string{ + utils.MetaTCC: utils.NOT_AVAILABLE, + utils.MetaTCD: utils.NOT_AVAILABLE, + } + if err := tutFsCallsRpc.Call(utils.StatSv1GetQueueStringMetrics, + &utils.TenantID{Tenant: "cgrates.org", ID: "Stats2"}, &metrics); err != nil { + t.Error(err) + } else if !reflect.DeepEqual(expectedMetrics, metrics) { + t.Errorf("expecting: %+v, received reply: %s", expectedMetrics, metrics) } } @@ -181,9 +188,9 @@ func testCallCheckResourceBeforeAllocation(t *testing.T) { CGREvent: utils.CGREvent{ Tenant: "cgrates.org", Event: map[string]interface{}{ - utils.Account: "1011", - utils.Subject: "1011", - utils.Destination: "1012"}, + utils.Account: "1001", + utils.Subject: "1001", + utils.Destination: "1002"}, }} if err := tutFsCallsRpc.Call(utils.ResourceSv1GetResourcesForEvent, args, &rs); err != nil { t.Error(err) @@ -191,7 +198,7 @@ func testCallCheckResourceBeforeAllocation(t *testing.T) { t.Errorf("Resources: %+v", utils.ToJSON(rs)) } for _, r := range *rs { - if r.ID == "ResGroup4" && + if r.ID == "ResGroup1" && (len(r.Usages) != 0 || len(r.TTLIdx) != 0) { t.Errorf("Unexpected resource: %+v", utils.ToJSON(r)) } @@ -200,9 +207,9 @@ func testCallCheckResourceBeforeAllocation(t *testing.T) { func testCallCheckThreshold1001Before(t *testing.T) { var td engine.Threshold - eTd := engine.Threshold{Tenant: "cgrates.org", ID: "THD_ACNT_1011", Hits: 0} + eTd := engine.Threshold{Tenant: "cgrates.org", ID: "THD_ACNT_1001", Hits: 0} if err := tutFsCallsRpc.Call(utils.ThresholdSv1GetThreshold, - &utils.TenantID{Tenant: "cgrates.org", ID: "THD_ACNT_1011"}, &td); err != nil { + &utils.TenantID{Tenant: "cgrates.org", ID: "THD_ACNT_1001"}, &td); err != nil { t.Error(err) } else if !reflect.DeepEqual(eTd, td) { t.Errorf("expecting: %+v, received: %+v", eTd, td) @@ -211,34 +218,39 @@ func testCallCheckThreshold1001Before(t *testing.T) { func testCallCheckThreshold1002Before(t *testing.T) { var td engine.Threshold - eTd := engine.Threshold{Tenant: "cgrates.org", ID: "THD_ACNT_1012", Hits: 0} + eTd := engine.Threshold{Tenant: "cgrates.org", ID: "THD_ACNT_1002", Hits: 0} if err := tutFsCallsRpc.Call(utils.ThresholdSv1GetThreshold, - &utils.TenantID{Tenant: "cgrates.org", ID: "THD_ACNT_1012"}, &td); err != nil { + &utils.TenantID{Tenant: "cgrates.org", ID: "THD_ACNT_1002"}, &td); err != nil { t.Error(err) } else if !reflect.DeepEqual(eTd, td) { t.Errorf("expecting: %+v, received: %+v", eTd, td) } } +// Start Pjsua as listener and register it to receive calls +func testCallStartPjsuaListener(t *testing.T) { + var err error + acnts := []*engine.PjsuaAccount{ + &engine.PjsuaAccount{Id: "sip:1001@192.168.56.202", + Username: "1001", Password: "CGRateS.org", Realm: "*", Registrar: "sip:192.168.56.202:5060"}, + &engine.PjsuaAccount{Id: "sip:1002@192.168.56.202", + Username: "1002", Password: "CGRateS.org", Realm: "*", Registrar: "sip:192.168.56.202:5060"}} + if tutFsCallsPjSuaListener, err = engine.StartPjsuaListener( + acnts, 5070, time.Duration(*waitRater)*time.Millisecond); err != nil { + t.Fatal(err) + } +} + // Call from 1001 (prepaid) to 1002 func testCallCall1001To1002(t *testing.T) { if err := engine.PjsuaCallUri( - &engine.PjsuaAccount{Id: "sip:1011@192.168.56.202", Username: "1011", Password: "CGRateS.org", Realm: "*"}, - "sip:1012@192.168.56.202", "sip:192.168.56.202:5060", time.Duration(67)*time.Second, 5071); err != nil { + &engine.PjsuaAccount{Id: "sip:1001@192.168.56.202", Username: "1001", Password: "CGRateS.org", Realm: "*"}, + "sip:1002@192.168.56.202", "sip:192.168.56.202:5060", time.Duration(67)*time.Second, 5071); err != nil { t.Fatal(err) } time.Sleep(1 * time.Second) } -// Call from 1002 (postpaid) to 1001 -func testCallCall1002To1001(t *testing.T) { - if err := engine.PjsuaCallUri( - &engine.PjsuaAccount{Id: "sip:1012@192.168.56.202", Username: "1012", Password: "CGRateS.org", Realm: "*"}, - "sip:1011@192.168.56.202", "sip:192.168.56.202:5060", time.Duration(65)*time.Second, 5072); err != nil { - t.Fatal(err) - } -} - // GetActiveSessions func testCallGetActiveSessions(t *testing.T) { var reply *[]*sessions.ActiveSession @@ -248,9 +260,9 @@ func testCallGetActiveSessions(t *testing.T) { ReqType: "*prepaid", Tenant: "cgrates.org", Category: "call", - Account: "1011", - Subject: "1011", - Destination: "1012", + Account: "1001", + Subject: "1001", + Destination: "1002", }, } if err := tutFsCallsRpc.Call("SessionSv1.GetActiveSessions", @@ -270,6 +282,24 @@ func testCallGetActiveSessions(t *testing.T) { } } +// Call from 1002 (postpaid) to 1001 +func testCallCall1002To1001(t *testing.T) { + if err := engine.PjsuaCallUri( + &engine.PjsuaAccount{Id: "sip:1002@192.168.56.202", Username: "1002", Password: "CGRateS.org", Realm: "*"}, + "sip:1001@192.168.56.202", "sip:192.168.56.202:5060", time.Duration(65)*time.Second, 5072); err != nil { + t.Fatal(err) + } +} + +// Call from 1001 (prepaid) to 1003 limit to 12 seconds +func testCallCall1001To1003(t *testing.T) { + if err := engine.PjsuaCallUri( + &engine.PjsuaAccount{Id: "sip:1001@192.168.56.202", Username: "1001", Password: "CGRateS.org", Realm: "*"}, + "sip:1003@192.168.56.202", "sip:192.168.56.202:5060", time.Duration(60)*time.Second, 5073); err != nil { + t.Fatal(err) + } +} + // Check if the resource was Allocated func testCallCheckResourceAllocation(t *testing.T) { var rs *engine.Resources @@ -277,9 +307,9 @@ func testCallCheckResourceAllocation(t *testing.T) { CGREvent: utils.CGREvent{ Tenant: "cgrates.org", Event: map[string]interface{}{ - utils.Account: "1011", - utils.Subject: "1011", - utils.Destination: "1012"}, + utils.Account: "1001", + utils.Subject: "1001", + utils.Destination: "1002"}, }} if err := tutFsCallsRpc.Call(utils.ResourceSv1GetResourcesForEvent, args, &rs); err != nil { t.Error(err) @@ -287,7 +317,7 @@ func testCallCheckResourceAllocation(t *testing.T) { t.Errorf("Resources: %+v", utils.ToJSON(rs)) } for _, r := range *rs { - if r.ID == "ResGroup4" && + if r.ID == "ResGroup1" && (len(r.Usages) != 1 || len(r.TTLIdx) != 1) { t.Errorf("Unexpected resource: %+v", utils.ToJSON(r)) } @@ -298,7 +328,7 @@ func testCallCheckResourceAllocation(t *testing.T) { func testCallAccount1001(t *testing.T) { time.Sleep(time.Duration(80) * time.Second) // Allow calls to finish before start querying the results var reply *engine.Account - attrs := &utils.AttrGetAccount{Tenant: "cgrates.org", Account: "1011"} + attrs := &utils.AttrGetAccount{Tenant: "cgrates.org", Account: "1001"} if err := tutFsCallsRpc.Call("ApierV2.GetAccount", attrs, &reply); err != nil { t.Error(err.Error()) } else if reply.BalanceMap[utils.MONETARY].GetTotalValue() == 10.0 { // Make sure we debitted @@ -308,57 +338,47 @@ func testCallAccount1001(t *testing.T) { } } -func testCallCheckThreshold1001After(t *testing.T) { - var td engine.Threshold - if err := tutFsCallsRpc.Call(utils.ThresholdSv1GetThreshold, - &utils.TenantID{Tenant: "cgrates.org", ID: "THD_ACNT_1011"}, &td); err != nil && - err.Error() != utils.ErrNotFound.Error() { - t.Error(err) - } -} +// Make sure account was debited properly +func testCall1001Cdrs(t *testing.T) { + var reply []*engine.ExternalCDR + req := utils.RPCCDRsFilter{RunIDs: []string{utils.META_DEFAULT}, Accounts: []string{"1001"}} + if err := tutFsCallsRpc.Call("ApierV2.GetCdrs", req, &reply); err != nil { + t.Error("Unexpected error: ", err.Error()) + } else if len(reply) != 2 { + t.Error("Unexpected number of CDRs returned: ", len(reply)) + } else { + for _, cdr := range reply { + if cdr.Source != "freeswitch_json" { + t.Errorf("Unexpected Source for CDR: %+v", cdr.Source) + } + if cdr.RequestType != utils.META_PREPAID { + t.Errorf("Unexpected RequestType for CDR: %+v", cdr.RequestType) + } + if cdr.Destination == "1002" { + if cdr.Usage != "1m7s" && cdr.Usage != "1m8s" { // Usage as seconds + t.Errorf("Unexpected Usage for CDR: %+v", cdr.Usage) + } + if cdr.CostSource != utils.MetaSessionS { + t.Errorf("Unexpected CostSource for CDR: %+v", cdr.CostSource) + } + } else { + if cdr.Usage != "12s" && cdr.Usage != "13s" { // Usage as seconds + t.Errorf("Unexpected Usage for CDR: %+v", cdr.Usage) + } + if cdr.CostSource != utils.MetaSessionS { + t.Errorf("Unexpected CostSource for CDR: %+v", cdr.CostSource) + } + } -func testCallCheckThreshold1002After(t *testing.T) { - var td engine.Threshold - eTd := engine.Threshold{Tenant: "cgrates.org", ID: "THD_ACNT_1012", Hits: 4} - if err := tutFsCallsRpc.Call(utils.ThresholdSv1GetThreshold, - &utils.TenantID{Tenant: "cgrates.org", ID: "THD_ACNT_1012"}, &td); err != nil { - t.Error(err) - } else if !reflect.DeepEqual(eTd.Tenant, td.Tenant) { - t.Errorf("expecting: %+v, received: %+v", eTd.Tenant, td.Tenant) - } else if !reflect.DeepEqual(eTd.ID, td.ID) { - t.Errorf("expecting: %+v, received: %+v", eTd.ID, td.ID) - } else if !reflect.DeepEqual(eTd.Hits, td.Hits) { - t.Errorf("expecting: %+v, received: %+v", eTd.Hits, td.Hits) - } -} - -func testCallCheckResourceRelease(t *testing.T) { - var rs *engine.Resources - args := &utils.ArgRSv1ResourceUsage{ - CGREvent: utils.CGREvent{ - Tenant: "cgrates.org", - Event: map[string]interface{}{ - utils.Account: "1011", - utils.Subject: "1011", - utils.Destination: "1012"}, - }} - if err := tutFsCallsRpc.Call(utils.ResourceSv1GetResourcesForEvent, args, &rs); err != nil { - t.Error(err) - } else if len(*rs) != 2 { - t.Errorf("Resources: %+v", rs) - } - for _, r := range *rs { - if r.ID == "ResGroup4" && - (len(r.Usages) != 0 || len(r.TTLIdx) != 0) { - t.Errorf("Unexpected resource: %+v", r) } + } } // Make sure account was debited properly -func testCall1001Cdrs(t *testing.T) { +func testCall1002Cdrs(t *testing.T) { var reply []*engine.ExternalCDR - req := utils.RPCCDRsFilter{RunIDs: []string{utils.META_DEFAULT}, Accounts: []string{"1011"}, DestinationPrefixes: []string{"1012"}} + req := utils.RPCCDRsFilter{RunIDs: []string{utils.META_DEFAULT}, Accounts: []string{"1002"}, DestinationPrefixes: []string{"1001"}} if err := tutFsCallsRpc.Call("ApierV2.GetCdrs", req, &reply); err != nil { t.Error("Unexpected error: ", err.Error()) } else if len(reply) != 1 { @@ -367,13 +387,13 @@ func testCall1001Cdrs(t *testing.T) { if reply[0].Source != "freeswitch_json" { t.Errorf("Unexpected Source for CDR: %+v", reply[0].Source) } - if reply[0].RequestType != utils.META_PREPAID { + if reply[0].RequestType != utils.META_POSTPAID { t.Errorf("Unexpected RequestType for CDR: %+v", reply[0].RequestType) } - if reply[0].Usage != "1m7s" { // Usage as seconds + if reply[0].Usage != "1m5s" { // Usage as seconds t.Errorf("Unexpected Usage for CDR: %+v", reply[0].Usage) } - if reply[0].CostSource != utils.MetaSessionS { + if reply[0].CostSource != utils.MetaCDRs { t.Errorf("Unexpected CostSource for CDR: %+v", reply[0].CostSource) } } @@ -393,6 +413,53 @@ func testCallStatMetrics(t *testing.T) { } } +func testCallCheckResourceRelease(t *testing.T) { + var rs *engine.Resources + args := &utils.ArgRSv1ResourceUsage{ + CGREvent: utils.CGREvent{ + Tenant: "cgrates.org", + Event: map[string]interface{}{ + utils.Account: "1001", + utils.Subject: "1001", + utils.Destination: "1002"}, + }} + if err := tutFsCallsRpc.Call(utils.ResourceSv1GetResourcesForEvent, args, &rs); err != nil { + t.Error(err) + } else if len(*rs) != 2 { + t.Errorf("Resources: %+v", rs) + } + for _, r := range *rs { + if r.ID == "ResGroup1" && + (len(r.Usages) != 0 || len(r.TTLIdx) != 0) { + t.Errorf("Unexpected resource: %+v", r) + } + } +} + +func testCallCheckThreshold1001After(t *testing.T) { + var td engine.Threshold + if err := tutFsCallsRpc.Call(utils.ThresholdSv1GetThreshold, + &utils.TenantID{Tenant: "cgrates.org", ID: "THD_ACNT_1001"}, &td); err != nil && + err.Error() != utils.ErrNotFound.Error() { + t.Error(err) + } +} + +func testCallCheckThreshold1002After(t *testing.T) { + var td engine.Threshold + eTd := engine.Threshold{Tenant: "cgrates.org", ID: "THD_ACNT_1002", Hits: 4} + if err := tutFsCallsRpc.Call(utils.ThresholdSv1GetThreshold, + &utils.TenantID{Tenant: "cgrates.org", ID: "THD_ACNT_1002"}, &td); err != nil { + t.Error(err) + } else if !reflect.DeepEqual(eTd.Tenant, td.Tenant) { + t.Errorf("expecting: %+v, received: %+v", eTd.Tenant, td.Tenant) + } else if !reflect.DeepEqual(eTd.ID, td.ID) { + t.Errorf("expecting: %+v, received: %+v", eTd.ID, td.ID) + } else if !reflect.DeepEqual(eTd.Hits, td.Hits) { + t.Errorf("expecting: %+v, received: %+v", eTd.Hits, td.Hits) + } +} + func testCallStopPjsuaListener(t *testing.T) { tutFsCallsPjSuaListener.Write([]byte("q\n")) // Close pjsua time.Sleep(time.Duration(1) * time.Second) // Allow pjsua to finish it's tasks, eg un-REGISTER