From 85000b4ca389fbda2d9b49561a4b79cce150487f Mon Sep 17 00:00:00 2001 From: Edwardro22 Date: Tue, 1 Aug 2017 16:24:38 +0300 Subject: [PATCH] added new fields --- apier/v1/apier_it_test.go | 2 +- .../mysql/create_tariffplan_tables.sql | 4 +++ .../postgres/create_tariffplan_tables.sql | 4 +++ data/tariffplans/testtp/ResourceLimits.csv | 12 ++++----- data/tariffplans/testtp/Stats.csv | 4 +-- data/tariffplans/tutorial/ResourceLimits.csv | 12 ++++----- data/tariffplans/tutorial/Stats.csv | 4 +-- engine/loader_csv_test.go | 14 ++++++---- engine/loader_it_test.go | 0 engine/model_helpers.go | 18 ++++++++++--- engine/model_helpers_test.go | 27 ++++++++++++++++--- engine/models.go | 10 ++++--- engine/reslimiter.go | 2 ++ engine/statsqueue.go | 2 ++ engine/stordb_it_test.go | 0 utils/apitpdata.go | 6 +++++ 16 files changed, 89 insertions(+), 32 deletions(-) mode change 100644 => 100755 data/tariffplans/testtp/ResourceLimits.csv mode change 100644 => 100755 data/tariffplans/testtp/Stats.csv mode change 100644 => 100755 data/tariffplans/tutorial/ResourceLimits.csv mode change 100644 => 100755 data/tariffplans/tutorial/Stats.csv mode change 100644 => 100755 engine/loader_it_test.go mode change 100644 => 100755 engine/reslimiter.go mode change 100644 => 100755 engine/stordb_it_test.go diff --git a/apier/v1/apier_it_test.go b/apier/v1/apier_it_test.go index 23aa8c7e6..0d6ad6587 100644 --- a/apier/v1/apier_it_test.go +++ b/apier/v1/apier_it_test.go @@ -1272,7 +1272,7 @@ func TestApierResetDataAfterLoadFromFolder(t *testing.T) { rcvStats.LcrProfiles != 0 || rcvStats.Aliases != 1 || rcvStats.ReverseAliases != 2 || - rcvStats.ResourceLimits != 0 { + rcvStats.ResourceLimits != 3 { t.Errorf("Expecting: %+v, received: %+v", expStats, rcvStats) } } diff --git a/data/storage/mysql/create_tariffplan_tables.sql b/data/storage/mysql/create_tariffplan_tables.sql index 2d2dda176..843007d40 100644 --- a/data/storage/mysql/create_tariffplan_tables.sql +++ b/data/storage/mysql/create_tariffplan_tables.sql @@ -407,6 +407,8 @@ CREATE TABLE tp_resource_limits ( `usage_ttl` varchar(32) NOT NULL, `limit` varchar(64) NOT NULL, `allocation_message` varchar(64) NOT NULL, + `blocker` BOOLEAN NOT NULL, + `stored` BOOLEAN NOT NULL, `weight` decimal(8,2) NOT NULL, `action_trigger_ids` varchar(64) NOT NULL, `created_at` TIMESTAMP, @@ -433,6 +435,8 @@ CREATE TABLE tp_stats ( `metrics` varchar(64) NOT NULL, `store` BOOLEAN NOT NULL, `thresholds` varchar(64) NOT NULL, + `blocker` BOOLEAN NOT NULL, + `stored` BOOLEAN NOT NULL, `weight` decimal(8,2) NOT NULL, `created_at` TIMESTAMP, PRIMARY KEY (`id`), diff --git a/data/storage/postgres/create_tariffplan_tables.sql b/data/storage/postgres/create_tariffplan_tables.sql index 9183881f1..3c9f34e6b 100644 --- a/data/storage/postgres/create_tariffplan_tables.sql +++ b/data/storage/postgres/create_tariffplan_tables.sql @@ -403,6 +403,8 @@ CREATE TABLE tp_resource_limits ( "usage_ttl" varchar(32) NOT NULL, "limit" varchar(64) NOT NULL, "allocation_message" varchar(64) NOT NULL, + "blocker" BOOLEAN NOT NULL, + "stored" BOOLEAN NOT NULL, "weight" NUMERIC(8,2) NOT NULL, "action_trigger_ids" varchar(64) NOT NULL, "created_at" TIMESTAMP WITH TIME ZONE @@ -429,6 +431,8 @@ CREATE TABLE tp_stats ( "metrics" varchar(64) NOT NULL, "store" BOOLEAN NOT NULL, "thresholds" varchar(64) NOT NULL, + "blocker" BOOLEAN NOT NULL, + "stored" BOOLEAN NOT NULL, "weight" decimal(8,2) NOT NULL, "created_at" TIMESTAMP WITH TIME ZONE ); diff --git a/data/tariffplans/testtp/ResourceLimits.csv b/data/tariffplans/testtp/ResourceLimits.csv old mode 100644 new mode 100755 index c95d6b485..8376db496 --- a/data/tariffplans/testtp/ResourceLimits.csv +++ b/data/tariffplans/testtp/ResourceLimits.csv @@ -1,6 +1,6 @@ -#Id,FilterType,FilterFieldName,FilterFieldValues,ActivationInterval,TTL,Limit,AllocationReply,Weight,ActionTriggers -ResGroup1,*string,Account,1001;1002,2014-07-29T15:00:00Z,1s,7,,20, -ResGroup1,*string_prefix,Destination,10;20,,,,,, -ResGroup1,*rsr_fields,,Subject(~^1.*1$);Destination(1002),,,,,, -ResGroup2,*destinations,Destination,DST_FS,2014-07-29T15:00:00Z,3600s,8,SPECIAL_1002,10, -ResGroup3,*cdr_stats,,CDRST1:*min_ASR:34;CDRST_1001:*min_ASR:20,,,,,, +#Id,FilterType,FilterFieldName,FilterFieldValues,ActivationInterval,TTL,Limit,AllocationReply,Blocker,Stored,Weight,ActionTriggers +ResGroup1,*string,Account,1001;1002,2014-07-29T15:00:00Z,1s,7,,true,true,20, +ResGroup1,*string_prefix,Destination,10;20,,,,,,,, +ResGroup1,*rsr_fields,,Subject(~^1.*1$);Destination(1002),,,,,,,, +ResGroup2,*destinations,Destination,DST_FS,2014-07-29T15:00:00Z,3600s,8,SPECIAL_1002,true,true,10, +ResGroup3,*cdr_stats,,CDRST1:*min_ASR:34;CDRST_1001:*min_ASR:20,,,,,,,, \ No newline at end of file diff --git a/data/tariffplans/testtp/Stats.csv b/data/tariffplans/testtp/Stats.csv old mode 100644 new mode 100755 index 8fdb9aa4d..3df799fc6 --- a/data/tariffplans/testtp/Stats.csv +++ b/data/tariffplans/testtp/Stats.csv @@ -1,2 +1,2 @@ -#Id,FilterType,FilterFieldName,FilterFieldValues,ActivationInterval,QueueLength,TTL,Metrics,Store,Thresholds,Weight -Stats1,*string,Account,1001;1002,2014-07-29T15:00:00Z,100,1s,*asr;*acd;*acc,true,THRESH1;THRESH2,20 +#Id,FilterType,FilterFieldName,FilterFieldValues,ActivationInterval,QueueLength,TTL,Metrics,Store,Thresholds,Blocker,Stored,Weight +Stats1,*string,Account,1001;1002,2014-07-29T15:00:00Z,100,1s,*asr;*acd;*acc,true,THRESH1;THRESH2,true,true,20 diff --git a/data/tariffplans/tutorial/ResourceLimits.csv b/data/tariffplans/tutorial/ResourceLimits.csv old mode 100644 new mode 100755 index c95d6b485..8376db496 --- a/data/tariffplans/tutorial/ResourceLimits.csv +++ b/data/tariffplans/tutorial/ResourceLimits.csv @@ -1,6 +1,6 @@ -#Id,FilterType,FilterFieldName,FilterFieldValues,ActivationInterval,TTL,Limit,AllocationReply,Weight,ActionTriggers -ResGroup1,*string,Account,1001;1002,2014-07-29T15:00:00Z,1s,7,,20, -ResGroup1,*string_prefix,Destination,10;20,,,,,, -ResGroup1,*rsr_fields,,Subject(~^1.*1$);Destination(1002),,,,,, -ResGroup2,*destinations,Destination,DST_FS,2014-07-29T15:00:00Z,3600s,8,SPECIAL_1002,10, -ResGroup3,*cdr_stats,,CDRST1:*min_ASR:34;CDRST_1001:*min_ASR:20,,,,,, +#Id,FilterType,FilterFieldName,FilterFieldValues,ActivationInterval,TTL,Limit,AllocationReply,Blocker,Stored,Weight,ActionTriggers +ResGroup1,*string,Account,1001;1002,2014-07-29T15:00:00Z,1s,7,,true,true,20, +ResGroup1,*string_prefix,Destination,10;20,,,,,,,, +ResGroup1,*rsr_fields,,Subject(~^1.*1$);Destination(1002),,,,,,,, +ResGroup2,*destinations,Destination,DST_FS,2014-07-29T15:00:00Z,3600s,8,SPECIAL_1002,true,true,10, +ResGroup3,*cdr_stats,,CDRST1:*min_ASR:34;CDRST_1001:*min_ASR:20,,,,,,,, \ No newline at end of file diff --git a/data/tariffplans/tutorial/Stats.csv b/data/tariffplans/tutorial/Stats.csv old mode 100644 new mode 100755 index 8fdb9aa4d..3df799fc6 --- a/data/tariffplans/tutorial/Stats.csv +++ b/data/tariffplans/tutorial/Stats.csv @@ -1,2 +1,2 @@ -#Id,FilterType,FilterFieldName,FilterFieldValues,ActivationInterval,QueueLength,TTL,Metrics,Store,Thresholds,Weight -Stats1,*string,Account,1001;1002,2014-07-29T15:00:00Z,100,1s,*asr;*acd;*acc,true,THRESH1;THRESH2,20 +#Id,FilterType,FilterFieldName,FilterFieldValues,ActivationInterval,QueueLength,TTL,Metrics,Store,Thresholds,Blocker,Stored,Weight +Stats1,*string,Account,1001;1002,2014-07-29T15:00:00Z,100,1s,*asr;*acd;*acc,true,THRESH1;THRESH2,true,true,20 diff --git a/engine/loader_csv_test.go b/engine/loader_csv_test.go index 0f12520b6..1a45df1f0 100755 --- a/engine/loader_csv_test.go +++ b/engine/loader_csv_test.go @@ -268,14 +268,14 @@ cgrates.org,mas,true,another,value,10 resLimits = ` #Id,FilterType,FilterFieldName,FilterFieldValues,ActivationInterval,TTL,Limit,AllocationMessage,Weight,ActionTriggers -ResGroup21,*string,HdrAccount,1001;1002,2014-07-29T15:00:00Z,1s,2,call,10, -ResGroup21,*string_prefix,HdrDestination,10;20,,,,,, -ResGroup21,*rsr_fields,,HdrSubject(~^1.*1$);HdrDestination(1002),,,,,, -ResGroup22,*destinations,HdrDestination,DST_FS,2014-07-29T15:00:00Z,3600s,2,premium_call,10, +ResGroup21,*string,HdrAccount,1001;1002,2014-07-29T15:00:00Z,1s,2,call,true,true,10, +ResGroup21,*string_prefix,HdrDestination,10;20,,,,,,,, +ResGroup21,*rsr_fields,,HdrSubject(~^1.*1$);HdrDestination(1002),,,,,,,, +ResGroup22,*destinations,HdrDestination,DST_FS,2014-07-29T15:00:00Z,3600s,2,premium_call,true,true,10, ` stats = ` #Id,FilterType,FilterFieldName,FilterFieldValues,ActivationInterval,QueueLength,TTL,Metrics,Store,Thresholds,Weight -Stats1,*string,Account,1001;1002,2014-07-29T15:00:00Z,100,1s,*asr;*acd;*acc,true,THRESH1;THRESH2,20 +Stats1,*string,Account,1001;1002,2014-07-29T15:00:00Z,100,1s,*asr;*acd;*acc,true,THRESH1;THRESH2,true,true,20 ` ) @@ -1408,6 +1408,8 @@ func TestLoadResourceLimits(t *testing.T) { }, UsageTTL: "3600s", AllocationMessage: "premium_call", + Blocker: true, + Stored: true, Weight: 10, Limit: "2", }, @@ -1436,6 +1438,8 @@ func TestLoadStats(t *testing.T) { Metrics: []string{"*asr", "*acd", "*acc"}, Store: true, Thresholds: []string{"THRESH1", "THRESH2"}, + Blocker: true, + Stored: true, Weight: 20, }, } diff --git a/engine/loader_it_test.go b/engine/loader_it_test.go old mode 100644 new mode 100755 diff --git a/engine/model_helpers.go b/engine/model_helpers.go index 90b20ae15..f07607133 100755 --- a/engine/model_helpers.go +++ b/engine/model_helpers.go @@ -1819,8 +1819,10 @@ func (tps TpResourceLimits) AsTPResourceLimits() (result []*utils.TPResourceLimi rl, found := mrl[tp.Tag] if !found { rl = &utils.TPResourceLimit{ - TPid: tp.Tpid, - ID: tp.Tag, + TPid: tp.Tpid, + ID: tp.Tag, + Blocker: tp.Blocker, + Stored: tp.Stored, } } if tp.UsageTTL != "" { @@ -1913,6 +1915,8 @@ func APItoResourceLimit(tpRL *utils.TPResourceLimit, timezone string) (rl *Resou rl = &ResourceLimit{ ID: tpRL.ID, Weight: tpRL.Weight, + Blocker: tpRL.Blocker, + Stored: tpRL.Stored, Filters: make([]*RequestFilter, len(tpRL.Filters)), Usage: make(map[string]*ResourceUsage), } @@ -1949,8 +1953,10 @@ func (tps TpStatsS) AsTPStats() (result []*utils.TPStats) { st, found := mst[tp.Tag] if !found { st = &utils.TPStats{ - TPid: tp.Tpid, - ID: tp.Tag, + TPid: tp.Tpid, + ID: tp.Tag, + Blocker: tp.Blocker, + Stored: tp.Stored, } } if tp.QueueLength != 0 { @@ -2015,6 +2021,8 @@ func APItoModelStats(st *utils.TPStats) (mdls TpStatsS) { } if i == 0 { mdl.TTL = st.TTL + mdl.Blocker = st.Blocker + mdl.Stored = st.Stored mdl.Weight = st.Weight mdl.QueueLength = st.QueueLength mdl.Store = st.Store @@ -2053,6 +2061,8 @@ func APItoTPStats(tpST *utils.TPStats, timezone string) (st *StatsQueue, err err QueueLength: tpST.QueueLength, Store: tpST.Store, Weight: tpST.Weight, + Blocker: tpST.Blocker, + Stored: tpST.Stored, Filters: make([]*RequestFilter, len(tpST.Filters)), } if tpST.TTL != "" { diff --git a/engine/model_helpers_test.go b/engine/model_helpers_test.go index 53b6ae304..56ddbf3e7 100644 --- a/engine/model_helpers_test.go +++ b/engine/model_helpers_test.go @@ -676,6 +676,8 @@ func TestTpResourceLimitsAsTPResourceLimits(t *testing.T) { FilterFieldName: "Destination", FilterFieldValues: "+49151;+49161", ActivationInterval: "2014-07-29T15:00:00Z", + Stored: false, + Blocker: false, Weight: 10.0, Limit: "45", ActionTriggerIds: "WARN_RES1;WARN_RES2"}, @@ -693,6 +695,8 @@ func TestTpResourceLimitsAsTPResourceLimits(t *testing.T) { FilterFieldName: "Destination", FilterFieldValues: "+40", ActivationInterval: "2014-07-29T15:00:00Z", + Stored: false, + Blocker: false, Weight: 10.0, Limit: "20"}, } @@ -715,6 +719,8 @@ func TestTpResourceLimitsAsTPResourceLimits(t *testing.T) { ActivationInterval: &utils.TPActivationInterval{ ActivationTime: tps[0].ActivationInterval, }, + Stored: tps[0].Stored, + Blocker: tps[0].Blocker, Weight: tps[0].Weight, Limit: tps[0].Limit, ActionTriggerIDs: []string{"WARN_RES1", "WARN_RES2", "WARN3"}, @@ -732,8 +738,10 @@ func TestTpResourceLimitsAsTPResourceLimits(t *testing.T) { ActivationInterval: &utils.TPActivationInterval{ ActivationTime: tps[2].ActivationInterval, }, - Weight: tps[2].Weight, - Limit: tps[2].Limit, + Stored: tps[2].Stored, + Blocker: tps[2].Blocker, + Weight: tps[2].Weight, + Limit: tps[2].Limit, }, } rcvTPs := TpResourceLimits(tps).AsTPResourceLimits() @@ -753,10 +761,15 @@ func TestAPItoResourceLimit(t *testing.T) { &utils.TPRequestFilter{Type: MetaRSRFields, Values: []string{"Subject(~^1.*1$)", "Destination(1002)"}}, }, ActivationInterval: &utils.TPActivationInterval{ActivationTime: "2014-07-29T15:00:00Z"}, + Stored: false, + Blocker: false, Weight: 10, Limit: "2", } - eRL := &ResourceLimit{ID: tpRL.ID, + eRL := &ResourceLimit{ + ID: tpRL.ID, + Stored: tpRL.Stored, + Blocker: tpRL.Blocker, Weight: tpRL.Weight, Filters: make([]*RequestFilter, len(tpRL.Filters)), Usage: make(map[string]*ResourceUsage)} @@ -797,6 +810,8 @@ func TestTPStatsAsTPStats(t *testing.T) { Metrics: "*asr;*acd;*acc", Store: true, Thresholds: "THRESH1;THRESH2", + Stored: false, + Blocker: false, Weight: 20.0, }, } @@ -819,6 +834,8 @@ func TestTPStatsAsTPStats(t *testing.T) { Metrics: []string{"*asr", "*acd", "*acc"}, Store: tps[0].Store, Thresholds: []string{"THRESH1", "THRESH2"}, + Stored: tps[0].Stored, + Blocker: tps[0].Blocker, Weight: tps[0].Weight, }, } @@ -841,6 +858,8 @@ func TestAPItoTPStats(t *testing.T) { Metrics: []string{"*asr", "*acd", "*acc"}, Store: true, Thresholds: []string{"THRESH1", "THRESH2"}, + Stored: false, + Blocker: false, Weight: 20.0, } @@ -850,6 +869,8 @@ func TestAPItoTPStats(t *testing.T) { Store: tps.Store, Thresholds: []string{"THRESH1", "THRESH2"}, Filters: make([]*RequestFilter, len(tps.Filters)), + Stored: tps.Stored, + Blocker: tps.Blocker, Weight: 20.0, } if eTPs.TTL, err = utils.ParseDurationWithSecs(tps.TTL); err != nil { diff --git a/engine/models.go b/engine/models.go index fbc28dc89..9ac3afc10 100755 --- a/engine/models.go +++ b/engine/models.go @@ -461,8 +461,10 @@ type TpResourceLimit struct { UsageTTL string `index:"5" re:""` Limit string `index:"6" re:""` AllocationMessage string `index:"7" re:""` - Weight float64 `index:"8" re:"\d+\.?\d*"` - ActionTriggerIds string `index:"9" re:""` + Blocker bool `index:"8" re:""` + Stored bool `index:"9" re:""` + Weight float64 `index:"10" re:"\d+\.?\d*"` + ActionTriggerIds string `index:"11" re:""` CreatedAt time.Time } @@ -489,6 +491,8 @@ type TpStats struct { Metrics string `index:"7" re:""` Store bool `index:"8" re:""` Thresholds string `index:"9" re:""` - Weight float64 `index:"10" re:"\d+\.?\d*"` + Blocker bool `index:"10" re:""` + Stored bool `index:"11" re:""` + Weight float64 `index:"12" re:"\d+\.?\d*"` CreatedAt time.Time } diff --git a/engine/reslimiter.go b/engine/reslimiter.go old mode 100644 new mode 100755 index 0c1e115b9..4bc4cb3d1 --- a/engine/reslimiter.go +++ b/engine/reslimiter.go @@ -42,6 +42,8 @@ type ResourceLimit struct { Filters []*RequestFilter // Filters for the request ActivationInterval *utils.ActivationInterval // Time when this limit becomes active and expires ExpiryTime time.Time + Blocker bool // blocker flag to stop processing on filters matched + Stored bool Weight float64 // Weight to sort the ResourceLimits Limit float64 // Limit value ActionTriggers ActionTriggers // Thresholds to check after changing Limit diff --git a/engine/statsqueue.go b/engine/statsqueue.go index 86221e7fe..43cd455c1 100755 --- a/engine/statsqueue.go +++ b/engine/statsqueue.go @@ -48,6 +48,8 @@ type StatsQueue struct { Metrics []string // list of metrics to build Store bool // store to DB Thresholds []string // list of thresholds to be checked after changes + Blocker bool // blocker flag to stop processing on filters matched + Stored bool Weight float64 } diff --git a/engine/stordb_it_test.go b/engine/stordb_it_test.go old mode 100644 new mode 100755 diff --git a/utils/apitpdata.go b/utils/apitpdata.go index c944278ed..0dccfe0e3 100755 --- a/utils/apitpdata.go +++ b/utils/apitpdata.go @@ -703,6 +703,8 @@ type CacheStats struct { Aliases int ReverseAliases int ResourceLimits int + //Stats int + //thresholds int } type AttrExpFileCdrs struct { @@ -1269,6 +1271,8 @@ type TPResourceLimit struct { UsageTTL string Limit string // Limit value AllocationMessage string + Blocker bool // blocker flag to stop processing on filters matched + Stored bool Weight float64 // Weight to sort the ResourceLimits ActionTriggerIDs []string // Thresholds to check after changing Limit } @@ -1334,5 +1338,7 @@ type TPStats struct { Metrics []string Store bool Thresholds []string + Blocker bool // blocker flag to stop processing on filters matched + Stored bool Weight float64 }