From 7b0f535d65f5747119b0365b33168e54eacaa2e3 Mon Sep 17 00:00:00 2001 From: TeoV Date: Fri, 29 Sep 2017 09:32:27 +0300 Subject: [PATCH] Remove MinItems from ThresholdProfiles and add/remote time.Sleep from resourcesv1_it_test.go and tp_it_test.go --- apier/v1/resourcesv1_it_test.go | 2 +- apier/v1/tp_it_test.go | 3 ++- data/storage/mysql/create_tariffplan_tables.sql | 5 +---- data/storage/postgres/create_tariffplan_tables.sql | 5 +---- data/tariffplans/testtp/Thresholds.csv | 4 ++-- data/tariffplans/tutorial/Thresholds.csv | 4 ++-- engine/loader_csv_test.go | 5 ++--- engine/model_helpers.go | 5 ----- engine/model_helpers_test.go | 4 ---- engine/models.go | 11 +++++------ engine/onstor_it_test.go | 1 - engine/storage_mongo_datadb.go | 2 +- engine/thresholds.go | 1 - utils/apitpdata.go | 1 - 14 files changed, 17 insertions(+), 36 deletions(-) diff --git a/apier/v1/resourcesv1_it_test.go b/apier/v1/resourcesv1_it_test.go index 42a6b03ad..96860e325 100644 --- a/apier/v1/resourcesv1_it_test.go +++ b/apier/v1/resourcesv1_it_test.go @@ -122,7 +122,6 @@ func testV1RsRpcConn(t *testing.T) { func testV1RsFromFolder(t *testing.T) { var reply string - time.Sleep(time.Duration(2000) * time.Millisecond) attrs := &utils.AttrLoadTpFromFolder{FolderPath: path.Join(*dataDir, "tariffplans", "tutorial")} if err := rlsV1Rpc.Call("ApierV1.LoadTariffPlanFromFolder", attrs, &reply); err != nil { t.Error(err) @@ -132,6 +131,7 @@ func testV1RsFromFolder(t *testing.T) { } func testV1RsGetResourcesForEvent(t *testing.T) { + time.Sleep(time.Duration(1000) * time.Millisecond) var reply *[]*engine.ResourceProfile args := &utils.ArgRSv1ResourceUsage{ Tenant: "cgrates.org", diff --git a/apier/v1/tp_it_test.go b/apier/v1/tp_it_test.go index a5d7c4f7e..b4c5c628e 100644 --- a/apier/v1/tp_it_test.go +++ b/apier/v1/tp_it_test.go @@ -84,7 +84,7 @@ func testTPInitCfg(t *testing.T) { config.SetCgrConfig(tpCfg) switch tpConfigDIR { case "tutmongo": // Mongo needs more time to reset db, need to investigate - tpDelay = 2000 + tpDelay = 4000 default: tpDelay = 2000 } @@ -114,6 +114,7 @@ func testTPRpcConn(t *testing.T) { } func testTPImportTPFromFolderPath(t *testing.T) { + time.Sleep(time.Duration(1 * time.Second)) var reply string if err := tpRPC.Call("ApierV1.ImportTariffPlanFromFolder", utils.AttrImportTPFromFolder{TPid: "TEST_TPID2", FolderPath: path.Join(tpDataDir, "tariffplans", "tutorial")}, &reply); err != nil { t.Error("Got error on ApierV1.ImportTarrifPlanFromFolder: ", err.Error()) diff --git a/data/storage/mysql/create_tariffplan_tables.sql b/data/storage/mysql/create_tariffplan_tables.sql index 8bd959e31..777109c9d 100644 --- a/data/storage/mysql/create_tariffplan_tables.sql +++ b/data/storage/mysql/create_tariffplan_tables.sql @@ -453,18 +453,15 @@ DROP TABLE IF EXISTS tp_thresholds; CREATE TABLE tp_thresholds ( `id` int(11) NOT NULL AUTO_INCREMENT, `tpid` varchar(64) NOT NULL, + `tenant` varchar(64) NOT NULL, `tag` varchar(64) NOT NULL, `filter_type` varchar(16) NOT NULL, `filter_field_name` varchar(64) NOT NULL, `filter_field_values` varchar(256) NOT NULL, `activation_interval` varchar(64) NOT NULL, - `threshold_type` char(64) NOT NULL, - `threshold_value` DECIMAL(20,4) NOT NULL, - `min_items` int(11) NOT NULL, `recurrent` BOOLEAN NOT NULL, `min_sleep` varchar(16) NOT NULL, `blocker` BOOLEAN NOT NULL, - `stored` BOOLEAN NOT NULL, `weight` decimal(8,2) NOT NULL, `action_ids` varchar(64) NOT NULL, `created_at` TIMESTAMP, diff --git a/data/storage/postgres/create_tariffplan_tables.sql b/data/storage/postgres/create_tariffplan_tables.sql index c2e9ef515..b9dbd986d 100644 --- a/data/storage/postgres/create_tariffplan_tables.sql +++ b/data/storage/postgres/create_tariffplan_tables.sql @@ -448,18 +448,15 @@ DROP TABLE IF EXISTS tp_thresholds; CREATE TABLE tp_thresholds ( "id" SERIAL PRIMARY KEY, "tpid" varchar(64) NOT NULL, + "tenant"varchar(64) NOT NULL, "tag" varchar(64) NOT NULL, "filter_type" varchar(16) NOT NULL, "filter_field_name" varchar(64) NOT NULL, "filter_field_values" varchar(256) NOT NULL, "activation_interval" varchar(64) NOT NULL, - "threshold_type" VARCHAR(64) NOT NULL, - "threshold_value" NUMERIC(20,4) NOT NULL, - "min_items" INTEGER NOT NULL, "recurrent" BOOLEAN NOT NULL, "min_sleep" varchar(16) NOT NULL, "blocker" BOOLEAN NOT NULL, - "stored" BOOLEAN NOT NULL, "weight" decimal(8,2) NOT NULL, "action_ids" varchar(64) NOT NULL, "created_at" TIMESTAMP WITH TIME ZONE diff --git a/data/tariffplans/testtp/Thresholds.csv b/data/tariffplans/testtp/Thresholds.csv index 9e629d669..a422ddaa6 100644 --- a/data/tariffplans/testtp/Thresholds.csv +++ b/data/tariffplans/testtp/Thresholds.csv @@ -1,2 +1,2 @@ -#Tenant[0],Id[1],FilterType[2],FilterFieldName[3],FilterFieldValues[4],ActivationInterval[5],MinItems[6],Recurrent[7],MinSleep[8],Blocker[9],Weight[10],ActionIDs[11] -cgrates.org,Threshold1,*string,Account,1001;1002,2014-07-29T15:00:00Z,10,true,1s,true,10,THRESH1;THRESH2 +#Tenant[0],Id[1],FilterType[2],FilterFieldName[3],FilterFieldValues[4],ActivationInterval[5],Recurrent[6],MinSleep[7],Blocker[8],Weight[9],ActionIDs[10] +cgrates.org,Threshold1,*string,Account,1001;1002,2014-07-29T15:00:00Z,true,1s,true,10,THRESH1;THRESH2 diff --git a/data/tariffplans/tutorial/Thresholds.csv b/data/tariffplans/tutorial/Thresholds.csv index 374a0342e..a422ddaa6 100644 --- a/data/tariffplans/tutorial/Thresholds.csv +++ b/data/tariffplans/tutorial/Thresholds.csv @@ -1,2 +1,2 @@ -#Tenant[0],Id[1],FilterType[2],FilterFieldName[3],FilterFieldValues[4],ActivationInterval[5],MinItems[6],Recurrent[7],MinSleep[8],Blocker[9],Weight[10],MinItems[11],ActionIDs[12] -cgrates.org,Threshold1,*string,Account,1001;1002,2014-07-29T15:00:00Z,10,true,1s,true,10,THRESH1;THRESH2 +#Tenant[0],Id[1],FilterType[2],FilterFieldName[3],FilterFieldValues[4],ActivationInterval[5],Recurrent[6],MinSleep[7],Blocker[8],Weight[9],ActionIDs[10] +cgrates.org,Threshold1,*string,Account,1001;1002,2014-07-29T15:00:00Z,true,1s,true,10,THRESH1;THRESH2 diff --git a/engine/loader_csv_test.go b/engine/loader_csv_test.go index 471030ccf..aedcc7624 100755 --- a/engine/loader_csv_test.go +++ b/engine/loader_csv_test.go @@ -278,8 +278,8 @@ cgrates.org,Stats1,*string,Account,1001;1002,2014-07-29T15:00:00Z,100,1s,*asr;*a ` thresholds = ` -#Tenant[0],Id[1],FilterType[2],FilterFieldName[3],FilterFieldValues[4],ActivationInterval[5],MinItems[6],Recurrent[7],MinSleep[8],Blocker[9],Weight[10],ActionIDs[11] -cgrates.org,Threshold1,*string,Account,1001;1002,2014-07-29T15:00:00Z,10,true,1s,true,10,THRESH1;THRESH2 +#Tenant[0],Id[1],FilterType[2],FilterFieldName[3],FilterFieldValues[4],ActivationInterval[5],Recurrent[6],MinSleep[7],Blocker[8],Weight[9],ActionIDs[10] +cgrates.org,Threshold1,*string,Account,1001;1002,2014-07-29T15:00:00Z,true,1s,true,10,THRESH1;THRESH2 ` ) @@ -1482,7 +1482,6 @@ func TestLoadThresholds(t *testing.T) { ActivationInterval: &utils.TPActivationInterval{ ActivationTime: "2014-07-29T15:00:00Z", }, - MinItems: 10, Recurrent: true, MinSleep: "1s", Blocker: true, diff --git a/engine/model_helpers.go b/engine/model_helpers.go index 235b98ea9..bc586d383 100755 --- a/engine/model_helpers.go +++ b/engine/model_helpers.go @@ -2137,9 +2137,6 @@ func (tps TpThresholdS) AsTPThreshold() (result []*utils.TPThreshold) { if tp.ActionIDs != "" { th.ActionIDs = append(th.ActionIDs, strings.Split(tp.ActionIDs, utils.INFIELD_SEP)...) } - if tp.MinItems != 0 { - th.MinItems = tp.MinItems - } if tp.Weight != 0 { th.Weight = tp.Weight } @@ -2182,7 +2179,6 @@ func APItoModelTPThreshold(th *utils.TPThreshold) (mdls TpThresholdS) { if i == 0 { mdl.Blocker = th.Blocker mdl.Weight = th.Weight - mdl.MinItems = th.MinItems mdl.Recurrent = th.Recurrent mdl.MinSleep = th.MinSleep if th.ActivationInterval != nil { @@ -2220,7 +2216,6 @@ func APItoThresholdProfile(tpTH *utils.TPThreshold, timezone string) (th *Thresh th = &ThresholdProfile{ Tenant: tpTH.Tenant, ID: tpTH.ID, - MinItems: tpTH.MinItems, Recurrent: tpTH.Recurrent, Weight: tpTH.Weight, Blocker: tpTH.Blocker, diff --git a/engine/model_helpers_test.go b/engine/model_helpers_test.go index d126748b7..937f79f85 100755 --- a/engine/model_helpers_test.go +++ b/engine/model_helpers_test.go @@ -940,7 +940,6 @@ func TestAsTPThresholdAsAsTPThreshold(t *testing.T) { FilterFieldName: "Account", FilterFieldValues: "1001;1002", ActivationInterval: "2014-07-29T15:00:00Z", - MinItems: 100, Recurrent: false, MinSleep: "1s", Blocker: false, @@ -962,7 +961,6 @@ func TestAsTPThresholdAsAsTPThreshold(t *testing.T) { ActivationInterval: &utils.TPActivationInterval{ ActivationTime: tps[0].ActivationInterval, }, - MinItems: tps[0].MinItems, MinSleep: tps[0].MinSleep, Recurrent: tps[0].Recurrent, Blocker: tps[0].Blocker, @@ -984,7 +982,6 @@ func TestAPItoTPThreshold(t *testing.T) { &utils.TPRequestFilter{Type: MetaString, FieldName: "Account", Values: []string{"1001", "1002"}}, }, ActivationInterval: &utils.TPActivationInterval{ActivationTime: "2014-07-29T15:00:00Z"}, - MinItems: 100, Recurrent: false, MinSleep: "1s", Blocker: false, @@ -995,7 +992,6 @@ func TestAPItoTPThreshold(t *testing.T) { eTPs := &ThresholdProfile{ ID: tps.ID, Filters: make([]*RequestFilter, len(tps.Filters)), - MinItems: tps.MinItems, Recurrent: tps.Recurrent, Blocker: tps.Blocker, Weight: tps.Weight, diff --git a/engine/models.go b/engine/models.go index 78ed32857..dad305048 100755 --- a/engine/models.go +++ b/engine/models.go @@ -508,11 +508,10 @@ type TpThreshold struct { FilterFieldName string `index:"3" re:""` FilterFieldValues string `index:"4" re:""` ActivationInterval string `index:"5" re:""` - MinItems int `index:"6" re:""` - Recurrent bool `index:"7" re:""` - MinSleep string `index:"8" re:""` - Blocker bool `index:"9" re:""` - Weight float64 `index:"10" re:"\d+\.?\d*"` - ActionIDs string `index:"11" re:""` + Recurrent bool `index:"6" re:""` + MinSleep string `index:"7" re:""` + Blocker bool `index:"8" re:""` + Weight float64 `index:"9" re:"\d+\.?\d*"` + ActionIDs string `index:"10" re:""` CreatedAt time.Time } diff --git a/engine/onstor_it_test.go b/engine/onstor_it_test.go index 4a69c302b..1703fab4d 100644 --- a/engine/onstor_it_test.go +++ b/engine/onstor_it_test.go @@ -2055,7 +2055,6 @@ func testOnStorITCRUDThresholdProfile(t *testing.T) { ID: "test", ActivationInterval: &utils.ActivationInterval{}, Filters: []*RequestFilter{}, - MinItems: 10, Recurrent: true, MinSleep: timeMinSleep, Blocker: true, diff --git a/engine/storage_mongo_datadb.go b/engine/storage_mongo_datadb.go index 2bc2a1ed4..903899e3e 100755 --- a/engine/storage_mongo_datadb.go +++ b/engine/storage_mongo_datadb.go @@ -718,7 +718,7 @@ func (ms *MongoStorage) HasData(category, subject string) (has bool, err error) case utils.StatQueuePrefix: count, err = db.C(colRes).Find(bson.M{"id": subject}).Count() has = count > 0 - case utils.ThresholdsPrefix: + case utils.ThresholdProfilePrefix: count, err = db.C(colThs).Find(bson.M{"id": subject}).Count() has = count > 0 default: diff --git a/engine/thresholds.go b/engine/thresholds.go index 80469e372..176565119 100644 --- a/engine/thresholds.go +++ b/engine/thresholds.go @@ -37,7 +37,6 @@ type ThresholdProfile struct { ID string Filters []*RequestFilter // Filters for the request ActivationInterval *utils.ActivationInterval // Time when this limit becomes active and expires - MinItems int // number of items agregated for the threshold to match Recurrent bool MinSleep time.Duration Blocker bool // blocker flag to stop processing on filters matched diff --git a/utils/apitpdata.go b/utils/apitpdata.go index cf7e209a8..48d5894b2 100755 --- a/utils/apitpdata.go +++ b/utils/apitpdata.go @@ -1360,7 +1360,6 @@ type TPThreshold struct { ID string Filters []*TPRequestFilter // Filters for the request ActivationInterval *TPActivationInterval // Time when this limit becomes active and expires - MinItems int // number of items agregated for the threshold to match Recurrent bool MinSleep string Blocker bool // blocker flag to stop processing on filters matched