From 9188aad445142da3b583358a21b24f17877332e7 Mon Sep 17 00:00:00 2001 From: TeoV Date: Fri, 15 Sep 2017 18:01:51 +0300 Subject: [PATCH 1/3] Small fix on data/storage/mysql and data/sorage/postgres --- data/storage/mysql/create_tariffplan_tables.sql | 8 ++++---- data/storage/postgres/create_tariffplan_tables.sql | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/data/storage/mysql/create_tariffplan_tables.sql b/data/storage/mysql/create_tariffplan_tables.sql index 3e2fe6fa3..8bd959e31 100644 --- a/data/storage/mysql/create_tariffplan_tables.sql +++ b/data/storage/mysql/create_tariffplan_tables.sql @@ -399,8 +399,8 @@ DROP TABLE IF EXISTS tp_resources; CREATE TABLE tp_resources ( `pk` int(11) NOT NULL AUTO_INCREMENT, `tpid` varchar(64) NOT NULL, - `id` varchar(64) NOT NULL, `tenant` varchar(64) NOT NULL, + `id` varchar(64) NOT NULL, `filter_type` varchar(16) NOT NULL, `filter_field_name` varchar(64) NOT NULL, `filter_field_values` varchar(256) NOT NULL, @@ -415,7 +415,7 @@ CREATE TABLE tp_resources ( `created_at` TIMESTAMP, PRIMARY KEY (`pk`), KEY `tpid` (`tpid`), - UNIQUE KEY `unique_tp_resource` (`tpid`, `id`, `filter_type`, `filter_field_name`) + UNIQUE KEY `unique_tp_resource` (`tpid`,`tenant`, `id`, `filter_type`, `filter_field_name`) ); -- @@ -424,9 +424,9 @@ CREATE TABLE tp_resources ( DROP TABLE IF EXISTS tp_stats; CREATE TABLE tp_stats ( - `tenant` varchar(64) NOT NULL, `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, @@ -442,7 +442,7 @@ CREATE TABLE tp_stats ( `created_at` TIMESTAMP, PRIMARY KEY (`id`), KEY `tpid` (`tpid`), - UNIQUE KEY `unique_tp_stats` (`tpid`, `tag`, `filter_type`, `filter_field_name`) + UNIQUE KEY `unique_tp_stats` (`tpid`, `tenant`, `tag`, `filter_type`, `filter_field_name`) ); -- diff --git a/data/storage/postgres/create_tariffplan_tables.sql b/data/storage/postgres/create_tariffplan_tables.sql index d065f2ca9..c2e9ef515 100644 --- a/data/storage/postgres/create_tariffplan_tables.sql +++ b/data/storage/postgres/create_tariffplan_tables.sql @@ -395,8 +395,8 @@ DROP TABLE IF EXISTS tp_resources; CREATE TABLE tp_resources ( "pk" SERIAL PRIMARY KEY, "tpid" varchar(64) NOT NULL, - "id" varchar(64) NOT NULL, "tenant"varchar(64) NOT NULL, + "id" varchar(64) NOT NULL, "filter_type" varchar(16) NOT NULL, "filter_field_name" varchar(64) NOT NULL, "filter_field_values" varchar(256) NOT NULL, @@ -411,7 +411,7 @@ CREATE TABLE tp_resources ( "created_at" TIMESTAMP WITH TIME ZONE ); CREATE INDEX tp_resources_idx ON tp_resources (tpid); -CREATE INDEX tp_resources_unique ON tp_resources ("tpid", "id", "filter_type", "filter_field_name"); +CREATE INDEX tp_resources_unique ON tp_resources ("tpid", "tenant", "id", "filter_type", "filter_field_name"); -- @@ -420,9 +420,9 @@ CREATE INDEX tp_resources_unique ON tp_resources ("tpid", "id", "filter_type", DROP TABLE IF EXISTS tp_stats; CREATE TABLE tp_stats ( - "tenant"varchar(64) NOT NULL, "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, @@ -438,7 +438,7 @@ CREATE TABLE tp_stats ( "created_at" TIMESTAMP WITH TIME ZONE ); CREATE INDEX tp_stats_idx ON tp_stats (tpid); -CREATE INDEX tp_stats_unique ON tp_stats ("tpid", "tag", "filter_type", "filter_field_name"); +CREATE INDEX tp_stats_unique ON tp_stats ("tpid","tenant", "tag", "filter_type", "filter_field_name"); -- -- Table structure for table `tp_threshold_cfgs` From da0746b9aa0ce4e3bc87af70d7c53849a978e770 Mon Sep 17 00:00:00 2001 From: TeoV Date: Fri, 15 Sep 2017 18:16:28 +0300 Subject: [PATCH 2/3] New check for TPid in apier/v2/tp.go --- apier/v2/tp.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/apier/v2/tp.go b/apier/v2/tp.go index 2053fc17e..99afc3c4d 100644 --- a/apier/v2/tp.go +++ b/apier/v2/tp.go @@ -30,8 +30,8 @@ type AttrRemTp struct { } func (self *ApierV2) RemTP(attrs AttrRemTp, reply *string) error { - if len(attrs.TPid) == 0 { - return utils.NewErrMandatoryIeMissing("TPid") + if missing := utils.MissingStructFields(&attrs, []string{"TPid"}); len(missing) != 0 { + return utils.NewErrMandatoryIeMissing(missing...) } if err := self.StorDb.RemTpData("", attrs.TPid, nil); err != nil { return utils.NewErrServerError(err) @@ -42,8 +42,8 @@ func (self *ApierV2) RemTP(attrs AttrRemTp, reply *string) error { } func (self *ApierV2) ExportTPToFolder(attrs utils.AttrDirExportTP, exported *utils.ExportedTPStats) error { - if len(*attrs.TPid) == 0 { - return utils.NewErrMandatoryIeMissing("TPid") + if missing := utils.MissingStructFields(&attrs, []string{"TPid", "ExportPath"}); len(missing) != 0 { + return utils.NewErrMandatoryIeMissing(missing...) } dir := self.Config.TpExportPath if attrs.ExportPath != nil { @@ -75,8 +75,8 @@ func (self *ApierV2) ExportTPToFolder(attrs utils.AttrDirExportTP, exported *uti } func (self *ApierV2) ExportTPToZipString(attrs utils.AttrDirExportTP, reply *string) error { - if len(*attrs.TPid) == 0 { - return utils.NewErrMandatoryIeMissing("TPid") + if missing := utils.MissingStructFields(&attrs, []string{"TPid"}); len(missing) != 0 { + return utils.NewErrMandatoryIeMissing(missing...) } dir := "" fileFormat := utils.CSV From 43c713f3a59100711f2a4b208ba77a55d1e9b17c Mon Sep 17 00:00:00 2001 From: TeoV Date: Fri, 15 Sep 2017 18:29:24 +0300 Subject: [PATCH 3/3] Fix on apier/v2/tp.go ExportTPToFolder --- apier/v2/tp.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/apier/v2/tp.go b/apier/v2/tp.go index 99afc3c4d..2513f87f0 100644 --- a/apier/v2/tp.go +++ b/apier/v2/tp.go @@ -30,8 +30,8 @@ type AttrRemTp struct { } func (self *ApierV2) RemTP(attrs AttrRemTp, reply *string) error { - if missing := utils.MissingStructFields(&attrs, []string{"TPid"}); len(missing) != 0 { - return utils.NewErrMandatoryIeMissing(missing...) + if len(attrs.TPid) == 0 { + return utils.NewErrMandatoryIeMissing("TPid") } if err := self.StorDb.RemTpData("", attrs.TPid, nil); err != nil { return utils.NewErrServerError(err) @@ -42,8 +42,8 @@ func (self *ApierV2) RemTP(attrs AttrRemTp, reply *string) error { } func (self *ApierV2) ExportTPToFolder(attrs utils.AttrDirExportTP, exported *utils.ExportedTPStats) error { - if missing := utils.MissingStructFields(&attrs, []string{"TPid", "ExportPath"}); len(missing) != 0 { - return utils.NewErrMandatoryIeMissing(missing...) + if attrs.TPid == nil || *attrs.TPid == "" { + return utils.NewErrMandatoryIeMissing("TPid") } dir := self.Config.TpExportPath if attrs.ExportPath != nil { @@ -75,8 +75,8 @@ func (self *ApierV2) ExportTPToFolder(attrs utils.AttrDirExportTP, exported *uti } func (self *ApierV2) ExportTPToZipString(attrs utils.AttrDirExportTP, reply *string) error { - if missing := utils.MissingStructFields(&attrs, []string{"TPid"}); len(missing) != 0 { - return utils.NewErrMandatoryIeMissing(missing...) + if attrs.TPid == nil || *attrs.TPid == "" { + return utils.NewErrMandatoryIeMissing("TPid") } dir := "" fileFormat := utils.CSV