diff --git a/db/init/mysql/schema.sql b/db/init/mysql/schema.sql index 4a96c40970db..36f9886e54ab 100644 --- a/db/init/mysql/schema.sql +++ b/db/init/mysql/schema.sql @@ -2371,8 +2371,59 @@ INSERT INTO `shenyu`.`permission` (`id`, `object_id`, `resource_id`, `date_creat INSERT INTO `shenyu`.`permission` (`id`, `object_id`, `resource_id`, `date_created`, `date_updated`) VALUES ('1792779493541343266', '1346358560427216896', '1792749362445840485', '2024-06-25 20:00:00.000', '2024-06-25 20:00:00.000'); INSERT INTO `shenyu`.`permission` (`id`, `object_id`, `resource_id`, `date_created`, `date_updated`) VALUES ('1792779493541343267', '1346358560427216896', '1792749362445840486', '2024-06-25 20:00:00.000', '2024-06-25 20:00:00.000'); +-- ---------------------------- +-- Table structure for scale +-- ---------------------------- +DROP TABLE IF EXISTS `scale_policy`; +CREATE TABLE IF NOT EXISTS `scale_policy` +( + `id` varchar(128) NOT NULL COMMENT 'primary key id', + `sort` int(0) NOT NULL COMMENT 'sort', + `status` int(0) NOT NULL COMMENT 'status 1:enable 0:disable', + `num` int COMMENT 'number of bootstrap', + `begin_time` datetime(3) COMMENT 'begin time', + `end_time` datetime(3) COMMENT 'end time', + `date_created` timestamp(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3) COMMENT 'create time', + `date_updated` timestamp(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3) ON UPDATE CURRENT_TIMESTAMP(3) COMMENT 'update time', + PRIMARY KEY (`id`) USING BTREE + ) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_unicode_ci ROW_FORMAT = Dynamic; + +INSERT INTO `shenyu`.`scale_policy` (`id`, `sort`, `status`, `num`, `begin_time`, `end_time`, `date_created`, `date_updated`) VALUES ('1', 1, 0, 10, NULL, NULL, '2024-07-31 20:00:00.000', '2024-07-31 20:00:00.000'); +INSERT INTO `shenyu`.`scale_policy` (`id`, `sort`, `status`, `num`, `begin_time`, `end_time`, `date_created`, `date_updated`) VALUES ('2', 2, 0, 10, '2024-07-31 20:00:00.000', '2024-08-01 20:00:00.000', '2024-07-31 20:00:00.000', '2024-07-31 20:00:00.000'); +INSERT INTO `shenyu`.`scale_policy` (`id`, `sort`, `status`, `num`, `begin_time`, `end_time`, `date_created`, `date_updated`) VALUES ('3', 3, 0, NULL, NULL, NULL, '2024-07-31 20:00:00.000', '2024-07-31 20:00:00.000'); + +DROP TABLE IF EXISTS `scale_rule`; +CREATE TABLE IF NOT EXISTS `scale_rule` +( + `id` varchar(128) NOT NULL COMMENT 'primary key id', + `metric_name` varchar(128) NOT NULL COMMENT 'metric name', + `type` int(0) NOT NULL COMMENT 'type 0:shenyu 1:k8s 2:others', + `sort` int(0) NOT NULL COMMENT 'sort', + `status` int(0) NOT NULL COMMENT 'status 1:enable 0:disable', + `minimum` varchar(128) COMMENT 'minimum of metric', + `maximum` varchar(128) COMMENT 'maximum of metric', + `date_created` timestamp(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3) COMMENT 'create time', + `date_updated` timestamp(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3) ON UPDATE CURRENT_TIMESTAMP(3) COMMENT 'update time', + PRIMARY KEY (`id`) USING BTREE + ) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_unicode_ci ROW_FORMAT = Dynamic; + +DROP TABLE IF EXISTS `scale_history`; +CREATE TABLE IF NOT EXISTS `scale_history` +( + `id` varchar(128) NOT NULL COMMENT 'primary key id', + `config_id` int(0) NOT NULL COMMENT '0:manual 1:period 2:dynamic', + `num` int NOT NULL COMMENT 'number of bootstrap', + `action` int(0) NOT NULL COMMENT 'status 1:enable 0:disable', + `msg` text COMMENT 'message', + `date_created` timestamp(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3) COMMENT 'create time', + `date_updated` timestamp(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3) ON UPDATE CURRENT_TIMESTAMP(3) COMMENT 'update time', + PRIMARY KEY (`id`) USING BTREE + ) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_unicode_ci ROW_FORMAT = Dynamic; + + ALTER TABLE `shenyu`.`selector` ADD COLUMN `namespace_id` varchar(50) NULL COMMENT 'namespaceId' AFTER `match_restful`; ALTER TABLE `shenyu`.`rule` ADD COLUMN `namespace_id` varchar(50) NULL COMMENT 'namespaceId' AFTER `match_restful`; -ALTER TABLE `shenyu`.`meta_data` ADD COLUMN `namespace_id` varchar(50) NULL COMMENT 'namespaceId'; \ No newline at end of file +ALTER TABLE `shenyu`.`meta_data` ADD COLUMN `namespace_id` varchar(50) NULL COMMENT 'namespaceId'; + diff --git a/db/init/og/create-table.sql b/db/init/og/create-table.sql index 398a487ca125..ed2fd66d5b28 100644 --- a/db/init/og/create-table.sql +++ b/db/init/og/create-table.sql @@ -2674,11 +2674,83 @@ INSERT INTO "public"."permission" VALUES ('1792779493541343266', '13463585604272 INSERT INTO "public"."permission" VALUES ('1792779493541343267', '1346358560427216896', '1792749362445840486', '2024-06-25 20:00:00.000', '2024-06-25 20:00:00.000'); +-- ---------------------------- +-- Table structure for scale +-- ---------------------------- +DROP TABLE IF EXISTS "public"."scale_policy"; +CREATE TABLE IF NOT EXISTS "public"."scale_policy" +( + "id" varchar(128) COLLATE "pg_catalog"."default" NOT NULL, + "sort" int4 NOT NULL, + "status" int2 NOT NULL, + "num" int4 , + "begin_time" timestamp(6) , + "end_time" timestamp(6) , + "date_created" timestamp(3) NOT NULL DEFAULT timezone('UTC-8'::text, (now())::timestamp(0) without time zone), + "date_updated" timestamp(3) NOT NULL DEFAULT timezone('UTC-8'::text, (now())::timestamp(0) without time zone) +); +COMMENT ON COLUMN "public"."scale_policy"."id" IS 'primary key id'; +COMMENT ON COLUMN "public"."scale_policy"."sort" IS 'sort'; +COMMENT ON COLUMN "public"."scale_policy"."status" IS 'status 1:enable 0:disable'; +COMMENT ON COLUMN "public"."scale_policy"."num" IS 'number of bootstrap'; +COMMENT ON COLUMN "public"."scale_policy"."begin_time" IS 'begin time'; +COMMENT ON COLUMN "public"."scale_policy"."end_time" IS 'end time'; +COMMENT ON COLUMN "public"."scale_policy"."date_created" IS 'create time'; +COMMENT ON COLUMN "public"."scale_policy"."date_updated" IS 'update time'; + +INSERT INTO "public"."scale_policy" VALUES ('1', 1, 0, 10, NULL, NULL, '2024-07-31 20:00:00.000', '2024-07-31 20:00:00.000'); +INSERT INTO "public"."scale_policy" VALUES ('2', 2, 0, 10, '2024-07-31 20:00:00.000', '2024-08-01 20:00:00.000', '2024-07-31 20:00:00.000', '2024-07-31 20:00:00.000'); +INSERT INTO "public"."scale_policy" VALUES ('3', 3, 0, NULL, NULL, NULL, '2024-07-31 20:00:00.000', '2024-07-31 20:00:00.000'); + +DROP TABLE IF EXISTS "public"."scale_rule"; +CREATE TABLE "public"."scale_rule" +( + "id" varchar(128) COLLATE "pg_catalog"."default" NOT NULL, + "metric_name" varchar(128) COLLATE "pg_catalog"."default" NOT NULL, + "type" int4 NOT NULL, + "sort" int4 NOT NULL, + "status" int2 NOT NULL, + "minimum" varchar(128) COLLATE "pg_catalog"."default", + "maximum" varchar(128) COLLATE "pg_catalog"."default", + "date_created" timestamp(3) NOT NULL DEFAULT timezone('UTC-8'::text, (now())::timestamp(0) without time zone), + "date_updated" timestamp(3) NOT NULL DEFAULT timezone('UTC-8'::text, (now())::timestamp(0) without time zone) +); +COMMENT ON COLUMN "public"."scale_rule"."id" IS 'primary key id'; +COMMENT ON COLUMN "public"."scale_rule"."metric_name" IS 'metric name'; +COMMENT ON COLUMN "public"."scale_rule"."type" IS 'type 0:shenyu 1:k8s 2:others'; +COMMENT ON COLUMN "public"."scale_rule"."sort" IS 'sort'; +COMMENT ON COLUMN "public"."scale_rule"."status" IS 'status 1:enable 0:disable'; +COMMENT ON COLUMN "public"."scale_rule"."minimum" IS 'minimum of metric'; +COMMENT ON COLUMN "public"."scale_rule"."maximum" IS 'maximum of metric'; +COMMENT ON COLUMN "public"."scale_rule"."date_created" IS 'create time'; +COMMENT ON COLUMN "public"."scale_rule"."date_updated" IS 'update time'; + +DROP TABLE IF EXISTS "public"."scale_history"; +CREATE TABLE "public"."scale_history" +( + "id" varchar(128) COLLATE "pg_catalog"."default" NOT NULL, + "config_id" int4 NOT NULL, + "num" int4 NOT NULL, + "action" int4 NOT NULL, + "msg" text COLLATE "pg_catalog"."default", + "date_created" timestamp(3) NOT NULL DEFAULT timezone('UTC-8'::text, (now())::timestamp(0) without time zone), + "date_updated" timestamp(3) NOT NULL DEFAULT timezone('UTC-8'::text, (now())::timestamp(0) without time zone) +); +COMMENT ON COLUMN "public"."scale_history"."id" IS 'primary key id'; +COMMENT ON COLUMN "public"."scale_history"."config_id" IS '0:manual 1:period 2:dynamic'; +COMMENT ON COLUMN "public"."scale_history"."num" IS 'number of bootstrap'; +COMMENT ON COLUMN "public"."scale_history"."action" IS 'status 1:enable 0:disable'; +COMMENT ON COLUMN "public"."scale_history"."msg" IS 'message'; +COMMENT ON COLUMN "public"."scale_history"."date_created" IS 'create time'; +COMMENT ON COLUMN "public"."scale_history"."date_updated" IS 'update time'; + + ALTER TABLE "public"."selector" ADD COLUMN namespace_id VARCHAR(50) NULL; COMMENT ON COLUMN "public"."selector"."namespace_id" IS 'namespaceId'; + ALTER TABLE "public"."rule" ADD COLUMN namespace_id VARCHAR(50) NULL; COMMENT ON COLUMN "public"."rule"."namespace_id" IS 'namespaceId'; ALTER TABLE "public"."meta_data" ADD COLUMN namespace_id VARCHAR(50) NULL; -COMMENT ON COLUMN "public"."meta_data"."namespace_id" IS 'namespaceId'; \ No newline at end of file +COMMENT ON COLUMN "public"."meta_data"."namespace_id" IS 'namespaceId'; diff --git a/db/init/oracle/schema.sql b/db/init/oracle/schema.sql index 27d708d87c36..86e6b3b7a608 100644 --- a/db/init/oracle/schema.sql +++ b/db/init/oracle/schema.sql @@ -2859,11 +2859,107 @@ INSERT /*+ IGNORE_ROW_ON_DUPKEY_INDEX (permission(id)) */ INTO permission (id, o INSERT /*+ IGNORE_ROW_ON_DUPKEY_INDEX (permission(id)) */ INTO permission (id, object_id, resource_id) VALUES ('1792779493541343267', '1346358560427216896', '1792749362445840486'); +-- ---------------------------- +-- Table structure for scale +-- ---------------------------- +create table scale_policy +( + id varchar(128) not null, + sort number not null, + status number not null, + num number, + begin_time timestamp(3), + end_time timestamp(3), + date_created timestamp(3) default SYSDATE not null, + date_updated timestamp(3) default SYSDATE not null, + PRIMARY KEY (id) +); +comment on column SCALE_POLICY.id + is 'primary key id'; +comment on column SCALE_POLICY.sort + is 'sort'; +comment on column SCALE_POLICY.status + is 'status 1:enable 0:disable'; +comment on column SCALE_POLICY.num + is 'number of bootstrap'; +comment on column SCALE_POLICY.begin_time + is 'begin time'; +comment on column SCALE_POLICY.end_time + is 'end time'; +comment on column SCALE_POLICY.date_created + is 'create time'; +comment on column SCALE_POLICY.date_updated + is 'update time'; + +INSERT /*+ IGNORE_ROW_ON_DUPKEY_INDEX (scale_policy(id)) */ INTO scale_policy (id, sort, status, num, begin_time, end_time, date_created, date_updated) VALUES ('1', 1, 0, 10, NULL, NULL, '2024-07-31 20:00:00.000', '2024-07-31 20:00:00.000'); +INSERT /*+ IGNORE_ROW_ON_DUPKEY_INDEX (scale_policy(id)) */ INTO scale_policy (id, sort, status, num, begin_time, end_time, date_created, date_updated) VALUES ('2', 2, 0, 10, '2024-07-31 20:00:00.000', '2024-08-01 20:00:00.000', '2024-07-31 20:00:00.000', '2024-07-31 20:00:00.000'); +INSERT /*+ IGNORE_ROW_ON_DUPKEY_INDEX (scale_policy(id)) */ INTO scale_policy (id, sort, status, num, begin_time, end_time, date_created, date_updated) VALUES ('3', 3, 0, NULL, NULL, NULL, '2024-07-31 20:00:00.000', '2024-07-31 20:00:00.000'); + +create table scale_rule +( + id varchar(128) not null, + metric_name varchar(128) not null, + type number not null, + sort number not null, + status number not null, + minimum varchar(128), + maximum varchar(128), + date_created timestamp(3) default SYSDATE not null, + date_updated timestamp(3) default SYSDATE not null, + PRIMARY KEY (id) +); +comment on column SCALE_RULE.id + is 'primary key id'; +comment on column SCALE_RULE.metric_name + is 'metric name'; +comment on column SCALE_RULE.type + is 'type 0:shenyu 1:k8s 2:others'; +comment on column SCALE_RULE.sort + is 'sort'; +comment on column SCALE_RULE.status + is 'status 1:enable 0:disable'; +comment on column SCALE_RULE.minimum + is 'minimum of metric'; +comment on column SCALE_RULE.maximum + is 'maximum of metric'; +comment on column SCALE_RULE.date_created + is 'create time'; +comment on column SCALE_RULE.date_updated + is 'update time'; + +create table scale_history +( + id varchar(128) not null, + config_id number not null, + num number not null, + action number not null, + msg clob, + date_created timestamp(3) default SYSDATE not null, + date_updated timestamp(3) default SYSDATE not null, + PRIMARY KEY (id) +); +comment on column SCALE_HISTORY.id + is 'primary key id'; +comment on column SCALE_HISTORY.config_id + is '0:manual 1:period 2:dynamic'; +comment on column SCALE_HISTORY.num + is 'number of bootstrap'; +comment on column SCALE_HISTORY.action + is 'status 1:enable 0:disable'; +comment on column SCALE_HISTORY.msg + is 'message'; +comment on column SCALE_HISTORY.date_created + is 'create time'; +comment on column SCALE_HISTORY.date_updated + is 'update time'; + + ALTER TABLE selector ADD namespace_id VARCHAR2(50) NULL; COMMENT ON COLUMN selector.namespace_id IS 'namespaceId'; + ALTER TABLE rule ADD namespace_id VARCHAR2(50) NULL; COMMENT ON COLUMN rule.namespace_id IS 'namespaceId'; ALTER TABLE meta_data ADD namespace_id VARCHAR2(50) NULL; -COMMENT ON COLUMN meta_data.namespace_id IS 'namespaceId'; \ No newline at end of file +COMMENT ON COLUMN meta_data.namespace_id IS 'namespaceId'; diff --git a/db/init/pg/create-table.sql b/db/init/pg/create-table.sql index bae10afbc3a2..32017aff07fd 100644 --- a/db/init/pg/create-table.sql +++ b/db/init/pg/create-table.sql @@ -2791,6 +2791,78 @@ INSERT INTO "public"."permission" VALUES ('1792779493541343265', '13463585604272 INSERT INTO "public"."permission" VALUES ('1792779493541343266', '1346358560427216896', '1792749362445840485', '2024-06-25 20:00:00.000', '2024-06-25 20:00:00.000'); INSERT INTO "public"."permission" VALUES ('1792779493541343267', '1346358560427216896', '1792749362445840486', '2024-06-25 20:00:00.000', '2024-06-25 20:00:00.000'); + +-- ---------------------------- +-- Table structure for scale +-- ---------------------------- +DROP TABLE IF EXISTS "public"."scale_policy"; +CREATE TABLE IF NOT EXISTS "public"."scale_policy" +( + "id" varchar(128) COLLATE "pg_catalog"."default" NOT NULL, + "sort" int4 NOT NULL, + "status" int2 NOT NULL, + "num" int4 , + "begin_time" timestamp(6) , + "end_time" timestamp(6) , + "date_created" timestamp(3) NOT NULL DEFAULT timezone('UTC-8'::text, (now())::timestamp(0) without time zone), + "date_updated" timestamp(3) NOT NULL DEFAULT timezone('UTC-8'::text, (now())::timestamp(0) without time zone) +); +COMMENT ON COLUMN "public"."scale_policy"."id" IS 'primary key id'; +COMMENT ON COLUMN "public"."scale_policy"."sort" IS 'sort'; +COMMENT ON COLUMN "public"."scale_policy"."status" IS 'status 1:enable 0:disable'; +COMMENT ON COLUMN "public"."scale_policy"."num" IS 'number of bootstrap'; +COMMENT ON COLUMN "public"."scale_policy"."begin_time" IS 'begin time'; +COMMENT ON COLUMN "public"."scale_policy"."end_time" IS 'end time'; +COMMENT ON COLUMN "public"."scale_policy"."date_created" IS 'create time'; +COMMENT ON COLUMN "public"."scale_policy"."date_updated" IS 'update time'; + +INSERT INTO "public"."scale_policy" VALUES ('1', 1, 0, 10, NULL, NULL, '2024-07-31 20:00:00.000', '2024-07-31 20:00:00.000'); +INSERT INTO "public"."scale_policy" VALUES ('2', 2, 0, 10, '2024-07-31 20:00:00.000', '2024-08-01 20:00:00.000', '2024-07-31 20:00:00.000', '2024-07-31 20:00:00.000'); +INSERT INTO "public"."scale_policy" VALUES ('3', 3, 0, NULL, NULL, NULL, '2024-07-31 20:00:00.000', '2024-07-31 20:00:00.000'); + +DROP TABLE IF EXISTS "public"."scale_rule"; +CREATE TABLE "public"."scale_rule" +( + "id" varchar(128) COLLATE "pg_catalog"."default" NOT NULL, + "metric_name" varchar(128) COLLATE "pg_catalog"."default" NOT NULL, + "type" int4 NOT NULL, + "sort" int4 NOT NULL, + "status" int2 NOT NULL, + "minimum" varchar(128) COLLATE "pg_catalog"."default", + "maximum" varchar(128) COLLATE "pg_catalog"."default", + "date_created" timestamp(3) NOT NULL DEFAULT timezone('UTC-8'::text, (now())::timestamp(0) without time zone), + "date_updated" timestamp(3) NOT NULL DEFAULT timezone('UTC-8'::text, (now())::timestamp(0) without time zone) +); +COMMENT ON COLUMN "public"."scale_rule"."id" IS 'primary key id'; +COMMENT ON COLUMN "public"."scale_rule"."metric_name" IS 'metric name'; +COMMENT ON COLUMN "public"."scale_rule"."type" IS 'type 0:shenyu 1:k8s 2:others'; +COMMENT ON COLUMN "public"."scale_rule"."sort" IS 'sort'; +COMMENT ON COLUMN "public"."scale_rule"."status" IS 'status 1:enable 0:disable'; +COMMENT ON COLUMN "public"."scale_rule"."minimum" IS 'minimum of metric'; +COMMENT ON COLUMN "public"."scale_rule"."maximum" IS 'maximum of metric'; +COMMENT ON COLUMN "public"."scale_rule"."date_created" IS 'create time'; +COMMENT ON COLUMN "public"."scale_rule"."date_updated" IS 'update time'; + +DROP TABLE IF EXISTS "public"."scale_history"; +CREATE TABLE "public"."scale_history" +( + "id" varchar(128) COLLATE "pg_catalog"."default" NOT NULL, + "config_id" int4 NOT NULL, + "num" int4 NOT NULL, + "action" int4 NOT NULL, + "msg" text COLLATE "pg_catalog"."default", + "date_created" timestamp(3) NOT NULL DEFAULT timezone('UTC-8'::text, (now())::timestamp(0) without time zone), + "date_updated" timestamp(3) NOT NULL DEFAULT timezone('UTC-8'::text, (now())::timestamp(0) without time zone) +); +COMMENT ON COLUMN "public"."scale_history"."id" IS 'primary key id'; +COMMENT ON COLUMN "public"."scale_history"."config_id" IS '0:manual 1:period 2:dynamic'; +COMMENT ON COLUMN "public"."scale_history"."num" IS 'number of bootstrap'; +COMMENT ON COLUMN "public"."scale_history"."action" IS 'status 1:enable 0:disable'; +COMMENT ON COLUMN "public"."scale_history"."msg" IS 'message'; +COMMENT ON COLUMN "public"."scale_history"."date_created" IS 'create time'; +COMMENT ON COLUMN "public"."scale_history"."date_updated" IS 'update time'; + + ALTER TABLE "public"."selector" ADD COLUMN namespace_id VARCHAR(50) NULL; COMMENT ON COLUMN "public"."selector"."namespace_id" IS 'namespaceId'; @@ -2798,4 +2870,4 @@ ALTER TABLE "public"."rule" ADD COLUMN namespace_id VARCHAR(50) NULL; COMMENT ON COLUMN "public"."rule"."namespace_id" IS 'namespaceId'; ALTER TABLE "public"."meta_data" ADD COLUMN namespace_id VARCHAR(50) NULL; -COMMENT ON COLUMN "public"."meta_data"."namespace_id" IS 'namespaceId'; \ No newline at end of file +COMMENT ON COLUMN "public"."meta_data"."namespace_id" IS 'namespaceId'; diff --git a/db/upgrade/2.6.1-upgrade-2.7.0-mysql.sql b/db/upgrade/2.6.1-upgrade-2.7.0-mysql.sql index b83bd1cc78f2..d129d44f082d 100755 --- a/db/upgrade/2.6.1-upgrade-2.7.0-mysql.sql +++ b/db/upgrade/2.6.1-upgrade-2.7.0-mysql.sql @@ -189,3 +189,54 @@ UPDATE meta_data SET namespace_id = '649330b6-c2d7-4edc-be8e-8a54df9eb385' WHERE namespace_id IS NULL; +-- ---------------------------- +-- Table structure for scale +-- ---------------------------- +DROP TABLE IF EXISTS `scale_policy`; +CREATE TABLE IF NOT EXISTS `scale_policy` +( + `id` varchar(128) NOT NULL COMMENT 'primary key id', + `sort` int(0) NOT NULL COMMENT 'sort', + `status` int(0) NOT NULL COMMENT 'status 1:enable 0:disable', + `num` int COMMENT 'number of bootstrap', + `begin_time` datetime(3) COMMENT 'begin time', + `end_time` datetime(3) COMMENT 'end time', + `date_created` timestamp(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3) COMMENT 'create time', + `date_updated` timestamp(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3) ON UPDATE CURRENT_TIMESTAMP(3) COMMENT 'update time', + PRIMARY KEY (`id`) USING BTREE + ) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_unicode_ci ROW_FORMAT = Dynamic; + +INSERT INTO `shenyu`.`scale_policy` (`id`, `sort`, `status`, `num`, `begin_time`, `end_time`, `date_created`, `date_updated`) VALUES ('1', 1, 0, 10, NULL, NULL, '2024-07-31 20:00:00.000', '2024-07-31 20:00:00.000'); +INSERT INTO `shenyu`.`scale_policy` (`id`, `sort`, `status`, `num`, `begin_time`, `end_time`, `date_created`, `date_updated`) VALUES ('2', 2, 0, 10, '2024-07-31 20:00:00.000', '2024-08-01 20:00:00.000', '2024-07-31 20:00:00.000', '2024-07-31 20:00:00.000'); +INSERT INTO `shenyu`.`scale_policy` (`id`, `sort`, `status`, `num`, `begin_time`, `end_time`, `date_created`, `date_updated`) VALUES ('3', 3, 0, NULL, NULL, NULL, '2024-07-31 20:00:00.000', '2024-07-31 20:00:00.000'); + +DROP TABLE IF EXISTS `scale_rule`; +CREATE TABLE IF NOT EXISTS `scale_rule` +( + `id` varchar(128) NOT NULL COMMENT 'primary key id', + `metric_name` varchar(128) NOT NULL COMMENT 'metric name', + `type` int(0) NOT NULL COMMENT 'type 0:shenyu 1:k8s 2:others', + `sort` int(0) NOT NULL COMMENT 'sort', + `status` int(0) NOT NULL COMMENT 'status 1:enable 0:disable', + `minimum` varchar(128) COMMENT 'minimum of metric', + `maximum` varchar(128) COMMENT 'maximum of metric', + `date_created` timestamp(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3) COMMENT 'create time', + `date_updated` timestamp(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3) ON UPDATE CURRENT_TIMESTAMP(3) COMMENT 'update time', + PRIMARY KEY (`id`) USING BTREE + ) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_unicode_ci ROW_FORMAT = Dynamic; + +DROP TABLE IF EXISTS `scale_history`; +CREATE TABLE IF NOT EXISTS `scale_history` +( + `id` varchar(128) NOT NULL COMMENT 'primary key id', + `config_id` int(0) NOT NULL COMMENT '0:manual 1:period 2:dynamic', + `num` int NOT NULL COMMENT 'number of bootstrap', + `action` int(0) NOT NULL COMMENT 'status 1:enable 0:disable', + `msg` text COMMENT 'message', + `date_created` timestamp(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3) COMMENT 'create time', + `date_updated` timestamp(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3) ON UPDATE CURRENT_TIMESTAMP(3) COMMENT 'update time', + PRIMARY KEY (`id`) USING BTREE + ) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_unicode_ci ROW_FORMAT = Dynamic; + + +ALTER TABLE `shenyu`.`selector` ADD COLUMN `namespace_id` varchar(50) NULL COMMENT 'namespaceId' AFTER `match_restful`; diff --git a/db/upgrade/2.6.1-upgrade-2.7.0-og.sql b/db/upgrade/2.6.1-upgrade-2.7.0-og.sql index 1ae2f669e541..1fced015b222 100644 --- a/db/upgrade/2.6.1-upgrade-2.7.0-og.sql +++ b/db/upgrade/2.6.1-upgrade-2.7.0-og.sql @@ -206,4 +206,74 @@ UPDATE "public"."rule" SET namespace_id = '649330b6-c2d7-4edc-be8e-8a54df9eb385' ALTER TABLE "public"."meta_data" ADD COLUMN namespace_id VARCHAR(50) NULL; COMMENT ON COLUMN "public"."meta_data"."namespace_id" IS 'namespaceId'; -UPDATE "public"."meta_data" SET namespace_id = '649330b6-c2d7-4edc-be8e-8a54df9eb385' WHERE namespace_id IS NULL; \ No newline at end of file +UPDATE "public"."meta_data" SET namespace_id = '649330b6-c2d7-4edc-be8e-8a54df9eb385' WHERE namespace_id IS NULL; + +-- ---------------------------- +-- Table structure for scale +-- ---------------------------- +DROP TABLE IF EXISTS "public"."scale_policy"; +CREATE TABLE IF NOT EXISTS "public"."scale_policy" +( + "id" varchar(128) COLLATE "pg_catalog"."default" NOT NULL, + "sort" int4 NOT NULL, + "status" int2 NOT NULL, + "num" int4 , + "begin_time" timestamp(6) , + "end_time" timestamp(6) , + "date_created" timestamp(3) NOT NULL DEFAULT timezone('UTC-8'::text, (now())::timestamp(0) without time zone), + "date_updated" timestamp(3) NOT NULL DEFAULT timezone('UTC-8'::text, (now())::timestamp(0) without time zone) + ); +COMMENT ON COLUMN "public"."scale_policy"."id" IS 'primary key id'; +COMMENT ON COLUMN "public"."scale_policy"."sort" IS 'sort'; +COMMENT ON COLUMN "public"."scale_policy"."status" IS 'status 1:enable 0:disable'; +COMMENT ON COLUMN "public"."scale_policy"."num" IS 'number of bootstrap'; +COMMENT ON COLUMN "public"."scale_policy"."begin_time" IS 'begin time'; +COMMENT ON COLUMN "public"."scale_policy"."end_time" IS 'end time'; +COMMENT ON COLUMN "public"."scale_policy"."date_created" IS 'create time'; +COMMENT ON COLUMN "public"."scale_policy"."date_updated" IS 'update time'; + +INSERT INTO "public"."scale_policy" VALUES ('1', 1, 0, 10, NULL, NULL, '2024-07-31 20:00:00.000', '2024-07-31 20:00:00.000'); +INSERT INTO "public"."scale_policy" VALUES ('2', 2, 0, 10, '2024-07-31 20:00:00.000', '2024-08-01 20:00:00.000', '2024-07-31 20:00:00.000', '2024-07-31 20:00:00.000'); +INSERT INTO "public"."scale_policy" VALUES ('3', 3, 0, NULL, NULL, NULL, '2024-07-31 20:00:00.000', '2024-07-31 20:00:00.000'); + +DROP TABLE IF EXISTS "public"."scale_rule"; +CREATE TABLE "public"."scale_rule" +( + "id" varchar(128) COLLATE "pg_catalog"."default" NOT NULL, + "metric_name" varchar(128) COLLATE "pg_catalog"."default" NOT NULL, + "type" int4 NOT NULL, + "sort" int4 NOT NULL, + "status" int2 NOT NULL, + "minimum" varchar(128) COLLATE "pg_catalog"."default", + "maximum" varchar(128) COLLATE "pg_catalog"."default", + "date_created" timestamp(3) NOT NULL DEFAULT timezone('UTC-8'::text, (now())::timestamp(0) without time zone), + "date_updated" timestamp(3) NOT NULL DEFAULT timezone('UTC-8'::text, (now())::timestamp(0) without time zone) +); +COMMENT ON COLUMN "public"."scale_rule"."id" IS 'primary key id'; +COMMENT ON COLUMN "public"."scale_rule"."metric_name" IS 'metric name'; +COMMENT ON COLUMN "public"."scale_rule"."type" IS 'type 0:shenyu 1:k8s 2:others'; +COMMENT ON COLUMN "public"."scale_rule"."sort" IS 'sort'; +COMMENT ON COLUMN "public"."scale_rule"."status" IS 'status 1:enable 0:disable'; +COMMENT ON COLUMN "public"."scale_rule"."minimum" IS 'minimum of metric'; +COMMENT ON COLUMN "public"."scale_rule"."maximum" IS 'maximum of metric'; +COMMENT ON COLUMN "public"."scale_rule"."date_created" IS 'create time'; +COMMENT ON COLUMN "public"."scale_rule"."date_updated" IS 'update time'; + +DROP TABLE IF EXISTS "public"."scale_history"; +CREATE TABLE "public"."scale_history" +( + "id" varchar(128) COLLATE "pg_catalog"."default" NOT NULL, + "config_id" int4 NOT NULL, + "num" int4 NOT NULL, + "action" int4 NOT NULL, + "msg" text COLLATE "pg_catalog"."default", + "date_created" timestamp(3) NOT NULL DEFAULT timezone('UTC-8'::text, (now())::timestamp(0) without time zone), + "date_updated" timestamp(3) NOT NULL DEFAULT timezone('UTC-8'::text, (now())::timestamp(0) without time zone) +); +COMMENT ON COLUMN "public"."scale_history"."id" IS 'primary key id'; +COMMENT ON COLUMN "public"."scale_history"."config_id" IS '0:manual 1:period 2:dynamic'; +COMMENT ON COLUMN "public"."scale_history"."num" IS 'number of bootstrap'; +COMMENT ON COLUMN "public"."scale_history"."action" IS 'status 1:enable 0:disable'; +COMMENT ON COLUMN "public"."scale_history"."msg" IS 'message'; +COMMENT ON COLUMN "public"."scale_history"."date_created" IS 'create time'; +COMMENT ON COLUMN "public"."scale_history"."date_updated" IS 'update time'; diff --git a/db/upgrade/2.6.1-upgrade-2.7.0-oracle.sql b/db/upgrade/2.6.1-upgrade-2.7.0-oracle.sql index b31e9c814730..abacb383bbf2 100755 --- a/db/upgrade/2.6.1-upgrade-2.7.0-oracle.sql +++ b/db/upgrade/2.6.1-upgrade-2.7.0-oracle.sql @@ -232,4 +232,98 @@ UPDATE rule SET namespace_id = '649330b6-c2d7-4edc-be8e-8a54df9eb385' WHERE name ALTER TABLE meta_data ADD namespace_id VARCHAR2(50) NULL; COMMENT ON COLUMN meta_data.namespace_id IS 'namespaceId'; -UPDATE meta_data SET namespace_id = '649330b6-c2d7-4edc-be8e-8a54df9eb385' WHERE namespace_id IS NULL; \ No newline at end of file +UPDATE meta_data SET namespace_id = '649330b6-c2d7-4edc-be8e-8a54df9eb385' WHERE namespace_id IS NULL; + +-- ---------------------------- +-- Table structure for scale +-- ---------------------------- +create table scale_policy +( + id varchar(128) not null, + sort number not null, + status number not null, + num number, + begin_time timestamp(3), + end_time timestamp(3), + date_created timestamp(3) default SYSDATE not null, + date_updated timestamp(3) default SYSDATE not null, + PRIMARY KEY (id) +); +comment on column SCALE_POLICY.id + is 'primary key id'; +comment on column SCALE_POLICY.sort + is 'sort'; +comment on column SCALE_POLICY.status + is 'status 1:enable 0:disable'; +comment on column SCALE_POLICY.num + is 'number of bootstrap'; +comment on column SCALE_POLICY.begin_time + is 'begin time'; +comment on column SCALE_POLICY.end_time + is 'end time'; +comment on column SCALE_POLICY.date_created + is 'create time'; +comment on column SCALE_POLICY.date_updated + is 'update time'; + +INSERT /*+ IGNORE_ROW_ON_DUPKEY_INDEX (scale_policy(id)) */ INTO scale_policy (id, sort, status, num, begin_time, end_time, date_created, date_updated) VALUES ('1', 1, 0, 10, NULL, NULL, '2024-07-31 20:00:00.000', '2024-07-31 20:00:00.000'); +INSERT /*+ IGNORE_ROW_ON_DUPKEY_INDEX (scale_policy(id)) */ INTO scale_policy (id, sort, status, num, begin_time, end_time, date_created, date_updated) VALUES ('2', 2, 0, 10, '2024-07-31 20:00:00.000', '2024-08-01 20:00:00.000', '2024-07-31 20:00:00.000', '2024-07-31 20:00:00.000'); +INSERT /*+ IGNORE_ROW_ON_DUPKEY_INDEX (scale_policy(id)) */ INTO scale_policy (id, sort, status, num, begin_time, end_time, date_created, date_updated) VALUES ('3', 3, 0, NULL, NULL, NULL, '2024-07-31 20:00:00.000', '2024-07-31 20:00:00.000'); + +create table scale_rule +( + id varchar(128) not null, + metric_name varchar(128) not null, + type number not null, + sort number not null, + status number not null, + minimum varchar(128), + maximum varchar(128), + date_created timestamp(3) default SYSDATE not null, + date_updated timestamp(3) default SYSDATE not null, + PRIMARY KEY (id) +); +comment on column SCALE_RULE.id + is 'primary key id'; +comment on column SCALE_RULE.metric_name + is 'metric name'; +comment on column SCALE_RULE.type + is 'type 0:shenyu 1:k8s 2:others'; +comment on column SCALE_RULE.sort + is 'sort'; +comment on column SCALE_RULE.status + is 'status 1:enable 0:disable'; +comment on column SCALE_RULE.minimum + is 'minimum of metric'; +comment on column SCALE_RULE.maximum + is 'maximum of metric'; +comment on column SCALE_RULE.date_created + is 'create time'; +comment on column SCALE_RULE.date_updated + is 'update time'; + +create table scale_history +( + id varchar(128) not null, + config_id number not null, + num number not null, + action number not null, + msg clob, + date_created timestamp(3) default SYSDATE not null, + date_updated timestamp(3) default SYSDATE not null, + PRIMARY KEY (id) +); +comment on column SCALE_HISTORY.id + is 'primary key id'; +comment on column SCALE_HISTORY.config_id + is '0:manual 1:period 2:dynamic'; +comment on column SCALE_HISTORY.num + is 'number of bootstrap'; +comment on column SCALE_HISTORY.action + is 'status 1:enable 0:disable'; +comment on column SCALE_HISTORY.msg + is 'message'; +comment on column SCALE_HISTORY.date_created + is 'create time'; +comment on column SCALE_HISTORY.date_updated + is 'update time'; diff --git a/db/upgrade/2.6.1-upgrade-2.7.0-pg.sql b/db/upgrade/2.6.1-upgrade-2.7.0-pg.sql index 55d068f2b537..cdffeab1fec4 100755 --- a/db/upgrade/2.6.1-upgrade-2.7.0-pg.sql +++ b/db/upgrade/2.6.1-upgrade-2.7.0-pg.sql @@ -207,4 +207,74 @@ UPDATE "public"."rule" SET namespace_id = '649330b6-c2d7-4edc-be8e-8a54df9eb385' ALTER TABLE "public"."meta_data" ADD COLUMN namespace_id VARCHAR(50) NULL; COMMENT ON COLUMN "public"."meta_data"."namespace_id" IS 'namespaceId'; -UPDATE "public"."meta_data" SET namespace_id = '649330b6-c2d7-4edc-be8e-8a54df9eb385' WHERE namespace_id IS NULL; \ No newline at end of file +UPDATE "public"."meta_data" SET namespace_id = '649330b6-c2d7-4edc-be8e-8a54df9eb385' WHERE namespace_id IS NULL; + +-- ---------------------------- +-- Table structure for scale +-- ---------------------------- +DROP TABLE IF EXISTS "public"."scale_policy"; +CREATE TABLE IF NOT EXISTS "public"."scale_policy" +( + "id" varchar(128) COLLATE "pg_catalog"."default" NOT NULL, + "sort" int4 NOT NULL, + "status" int2 NOT NULL, + "num" int4 , + "begin_time" timestamp(6) , + "end_time" timestamp(6) , + "date_created" timestamp(3) NOT NULL DEFAULT timezone('UTC-8'::text, (now())::timestamp(0) without time zone), + "date_updated" timestamp(3) NOT NULL DEFAULT timezone('UTC-8'::text, (now())::timestamp(0) without time zone) + ); +COMMENT ON COLUMN "public"."scale_policy"."id" IS 'primary key id'; +COMMENT ON COLUMN "public"."scale_policy"."sort" IS 'sort'; +COMMENT ON COLUMN "public"."scale_policy"."status" IS 'status 1:enable 0:disable'; +COMMENT ON COLUMN "public"."scale_policy"."num" IS 'number of bootstrap'; +COMMENT ON COLUMN "public"."scale_policy"."begin_time" IS 'begin time'; +COMMENT ON COLUMN "public"."scale_policy"."end_time" IS 'end time'; +COMMENT ON COLUMN "public"."scale_policy"."date_created" IS 'create time'; +COMMENT ON COLUMN "public"."scale_policy"."date_updated" IS 'update time'; + +INSERT INTO "public"."scale_policy" VALUES ('1', 1, 0, 10, NULL, NULL, '2024-07-31 20:00:00.000', '2024-07-31 20:00:00.000'); +INSERT INTO "public"."scale_policy" VALUES ('2', 2, 0, 10, '2024-07-31 20:00:00.000', '2024-08-01 20:00:00.000', '2024-07-31 20:00:00.000', '2024-07-31 20:00:00.000'); +INSERT INTO "public"."scale_policy" VALUES ('3', 3, 0, NULL, NULL, NULL, '2024-07-31 20:00:00.000', '2024-07-31 20:00:00.000'); + +DROP TABLE IF EXISTS "public"."scale_rule"; +CREATE TABLE "public"."scale_rule" +( + "id" varchar(128) COLLATE "pg_catalog"."default" NOT NULL, + "metric_name" varchar(128) COLLATE "pg_catalog"."default" NOT NULL, + "type" int4 NOT NULL, + "sort" int4 NOT NULL, + "status" int2 NOT NULL, + "minimum" varchar(128) COLLATE "pg_catalog"."default", + "maximum" varchar(128) COLLATE "pg_catalog"."default", + "date_created" timestamp(3) NOT NULL DEFAULT timezone('UTC-8'::text, (now())::timestamp(0) without time zone), + "date_updated" timestamp(3) NOT NULL DEFAULT timezone('UTC-8'::text, (now())::timestamp(0) without time zone) +); +COMMENT ON COLUMN "public"."scale_rule"."id" IS 'primary key id'; +COMMENT ON COLUMN "public"."scale_rule"."metric_name" IS 'metric name'; +COMMENT ON COLUMN "public"."scale_rule"."type" IS 'type 0:shenyu 1:k8s 2:others'; +COMMENT ON COLUMN "public"."scale_rule"."sort" IS 'sort'; +COMMENT ON COLUMN "public"."scale_rule"."status" IS 'status 1:enable 0:disable'; +COMMENT ON COLUMN "public"."scale_rule"."minimum" IS 'minimum of metric'; +COMMENT ON COLUMN "public"."scale_rule"."maximum" IS 'maximum of metric'; +COMMENT ON COLUMN "public"."scale_rule"."date_created" IS 'create time'; +COMMENT ON COLUMN "public"."scale_rule"."date_updated" IS 'update time'; + +DROP TABLE IF EXISTS "public"."scale_history"; +CREATE TABLE "public"."scale_history" +( + "id" varchar(128) COLLATE "pg_catalog"."default" NOT NULL, + "config_id" int4 NOT NULL, + "num" int4 NOT NULL, + "action" int4 NOT NULL, + "msg" text COLLATE "pg_catalog"."default", + "date_created" timestamp(3) NOT NULL DEFAULT timezone('UTC-8'::text, (now())::timestamp(0) without time zone), + "date_updated" timestamp(3) NOT NULL DEFAULT timezone('UTC-8'::text, (now())::timestamp(0) without time zone) +); +COMMENT ON COLUMN "public"."scale_history"."id" IS 'primary key id'; +COMMENT ON COLUMN "public"."scale_history"."config_id" IS '0:manual 1:period 2:dynamic'; +COMMENT ON COLUMN "public"."scale_history"."num" IS 'number of bootstrap'; +COMMENT ON COLUMN "public"."scale_history"."action" IS 'status 1:enable 0:disable'; +COMMENT ON COLUMN "public"."scale_history"."msg" IS 'message'; +COMMENT ON COLUMN "public"."scale_history"."date_created" IS 'create time'; +COMMENT ON COLUMN "public"."scale_history"."date_updated" IS 'update time'; diff --git a/shenyu-admin/src/main/java/org/apache/shenyu/admin/controller/ScalePolicyController.java b/shenyu-admin/src/main/java/org/apache/shenyu/admin/controller/ScalePolicyController.java new file mode 100644 index 000000000000..46dce27b3424 --- /dev/null +++ b/shenyu-admin/src/main/java/org/apache/shenyu/admin/controller/ScalePolicyController.java @@ -0,0 +1,85 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.shenyu.admin.controller; + +import jakarta.validation.Valid; +import org.apache.shenyu.admin.aspect.annotation.RestApi; +import org.apache.shenyu.admin.mapper.ScalePolicyMapper; +import org.apache.shenyu.admin.model.dto.ScalePolicyDTO; +import org.apache.shenyu.admin.model.result.ShenyuAdminResult; +import org.apache.shenyu.admin.model.vo.ScalePolicyVO; +import org.apache.shenyu.admin.service.ScalePolicyService; +import org.apache.shenyu.admin.utils.ShenyuResultMessage; +import org.apache.shenyu.admin.validation.annotation.Existed; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PutMapping; +import org.springframework.web.bind.annotation.RequestBody; + +import java.util.Optional; + +/** + * this is ScalePolicy controller. + */ +@RestApi("/scale/policy") +public class ScalePolicyController { + + private final ScalePolicyService scalePolicyService; + + public ScalePolicyController(final ScalePolicyService scalePolicyService) { + this.scalePolicyService = scalePolicyService; + } + + /** + * get all policies. + * + * @return ShenyuAdminResult + */ + @GetMapping("/getAllPolicies") + public ShenyuAdminResult selectAll() { + return ShenyuAdminResult.success(ShenyuResultMessage.QUERY_SUCCESS, scalePolicyService.selectAll()); + } + + /** + * detail scale policy. + * + * @param id primary key + * @return ShenyuAdminResult + */ + @GetMapping("/{id}") + public ShenyuAdminResult detailPolicy(@PathVariable("id") + @Valid + @Existed(provider = ScalePolicyMapper.class, + message = "scale policy is not existed") final String id) { + ScalePolicyVO scalePolicyVO = scalePolicyService.findById(id); + return Optional.ofNullable(scalePolicyVO) + .map(item -> ShenyuAdminResult.success(ShenyuResultMessage.DETAIL_SUCCESS, item)) + .orElse(ShenyuAdminResult.error(ShenyuResultMessage.DETAIL_FAILED)); + } + + /** + * update scale policy. + * + * @param scalePolicyDTO scale policy info + * @return ShenyuAdminResult + */ + @PutMapping + public ShenyuAdminResult updateScalePolicy(@Valid @RequestBody final ScalePolicyDTO scalePolicyDTO) { + return ShenyuAdminResult.success(ShenyuResultMessage.UPDATE_SUCCESS, scalePolicyService.update(scalePolicyDTO)); + } +} diff --git a/shenyu-admin/src/main/java/org/apache/shenyu/admin/controller/ScaleRlueController.java b/shenyu-admin/src/main/java/org/apache/shenyu/admin/controller/ScaleRlueController.java new file mode 100644 index 000000000000..338585508ae9 --- /dev/null +++ b/shenyu-admin/src/main/java/org/apache/shenyu/admin/controller/ScaleRlueController.java @@ -0,0 +1,134 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.shenyu.admin.controller; + +import jakarta.validation.Valid; +import jakarta.validation.constraints.NotBlank; +import jakarta.validation.constraints.NotEmpty; +import jakarta.validation.constraints.NotNull; +import org.apache.shenyu.admin.aspect.annotation.RestApi; +import org.apache.shenyu.admin.mapper.ScaleRuleMapper; +import org.apache.shenyu.admin.model.dto.ScaleRuleDTO; +import org.apache.shenyu.admin.model.page.CommonPager; +import org.apache.shenyu.admin.model.page.PageParameter; +import org.apache.shenyu.admin.model.query.ScaleRuleQuery; +import org.apache.shenyu.admin.model.result.ShenyuAdminResult; +import org.apache.shenyu.admin.model.vo.ScaleRuleVO; +import org.apache.shenyu.admin.service.ScaleRuleService; +import org.apache.shenyu.admin.utils.ShenyuResultMessage; +import org.apache.shenyu.admin.validation.annotation.Existed; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.PutMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.DeleteMapping; + +import java.util.List; +import java.util.Optional; + +/** + * this is scale rule controller. + */ +@RestApi("/scale/rule") +public class ScaleRlueController { + + private final ScaleRuleService scaleRuleService; + + public ScaleRlueController(final ScaleRuleService scaleRuleService) { + this.scaleRuleService = scaleRuleService; + } + + /** + * get all rules. + * + * @return ShenyuAdminResult + */ + @GetMapping("/getAllRules") + public ShenyuAdminResult selectAll() { + return ShenyuAdminResult.success(ShenyuResultMessage.QUERY_SUCCESS, scaleRuleService.selectAll()); + } + + /** + * query scale rule. + * + * @param metricName metricName + * @param currentPage currentPage + * @param pageSize pageSize + * @return org.apache.shenyu.admin.model.result.ShenyuAdminResult + */ + @GetMapping + public ShenyuAdminResult queryRule(final String metricName, + @RequestParam @NotNull final Integer currentPage, + @RequestParam @NotNull final Integer pageSize) { + CommonPager commonPager = + scaleRuleService.listByPage(new ScaleRuleQuery(metricName, new PageParameter(currentPage, pageSize))); + return ShenyuAdminResult.success(ShenyuResultMessage.QUERY_SUCCESS, commonPager); + } + + /** + * detail scale rule. + * + * @param id id + * @return ShenyuAdminResult + */ + @GetMapping("/{id}") + public ShenyuAdminResult detailRule(@PathVariable("id") + @Valid + @Existed(provider = ScaleRuleMapper.class, + message = "scale role is not existed") final String id) { + ScaleRuleVO scaleRuleVO = scaleRuleService.findById(id); + return Optional.ofNullable(scaleRuleVO) + .map(item -> ShenyuAdminResult.success(ShenyuResultMessage.DETAIL_SUCCESS, item)) + .orElse(ShenyuAdminResult.error(ShenyuResultMessage.DETAIL_FAILED)); + } + + /** + * create scale rule. + * + * @param scaleRuleDTO scaleRuleDTO + * @return ShenyuAdminResult + */ + @PostMapping + public ShenyuAdminResult createRule(@Valid @RequestBody final ScaleRuleDTO scaleRuleDTO) { + return ShenyuAdminResult.success(ShenyuResultMessage.CREATE_SUCCESS, scaleRuleService.createOrUpdate(scaleRuleDTO)); + } + + /** + * update rule. + * + * @param scaleRuleDTO scaleRuleDTO + * @return ShenyuAdminResult + */ + @PutMapping + public ShenyuAdminResult updateRule(@Valid @RequestBody final ScaleRuleDTO scaleRuleDTO) { + return ShenyuAdminResult.success(ShenyuResultMessage.UPDATE_SUCCESS, scaleRuleService.createOrUpdate(scaleRuleDTO)); + } + + /** + * delete rules. + * + * @param ids ids + * @return ShenyuAdminResult + */ + @DeleteMapping("/batch") + public ShenyuAdminResult deleteRules(@RequestBody @NotEmpty final List<@NotBlank String> ids) { + return ShenyuAdminResult.success(ShenyuResultMessage.DELETE_SUCCESS, scaleRuleService.delete(ids)); + } +} diff --git a/shenyu-admin/src/main/java/org/apache/shenyu/admin/mapper/ScaleHistoryMapper.java b/shenyu-admin/src/main/java/org/apache/shenyu/admin/mapper/ScaleHistoryMapper.java new file mode 100644 index 000000000000..e1fd76cb1ff0 --- /dev/null +++ b/shenyu-admin/src/main/java/org/apache/shenyu/admin/mapper/ScaleHistoryMapper.java @@ -0,0 +1,106 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.shenyu.admin.mapper; + +import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; +import org.apache.shenyu.admin.model.entity.ScaleHistoryDO; +import org.apache.shenyu.admin.validation.ExistProvider; + +import java.io.Serializable; +import java.util.List; + +/** + * ScaleHistory Mapper. + */ +@Mapper +public interface ScaleHistoryMapper extends ExistProvider { + + /** + * scale history existed. + * + * @param id id + * @return Boolean + */ + @Override + Boolean existed(@Param("id") Serializable id); + + /** + * deleteByPrimaryKey. + * + * @param id id + * @return int + */ + int deleteByPrimaryKey(String id); + + /** + * insert. + * + * @param row row + * @return int + */ + int insert(ScaleHistoryDO row); + + /** + * insertSelective. + * + * @param row row + * @return int + */ + int insertSelective(ScaleHistoryDO row); + + /** + * selectByPrimaryKey. + * + * @param id id + * @return ScaleHistoryDO + */ + ScaleHistoryDO selectByPrimaryKey(String id); + + /** + * updateByPrimaryKeySelective. + * + * @param row row + * @return int + */ + int updateByPrimaryKeySelective(ScaleHistoryDO row); + + /** + * updateByPrimaryKeyWithBLOBs. + * + * @param row row + * @return int + */ + int updateByPrimaryKeyWithBLOBs(ScaleHistoryDO row); + + /** + * updateByPrimaryKey. + * + * @param row row + * @return int + */ + int updateByPrimaryKey(ScaleHistoryDO row); + + + /** + * select all. + * + * @return List + */ + List selectAll(); +} diff --git a/shenyu-admin/src/main/java/org/apache/shenyu/admin/mapper/ScalePolicyMapper.java b/shenyu-admin/src/main/java/org/apache/shenyu/admin/mapper/ScalePolicyMapper.java new file mode 100644 index 000000000000..3823b8195b18 --- /dev/null +++ b/shenyu-admin/src/main/java/org/apache/shenyu/admin/mapper/ScalePolicyMapper.java @@ -0,0 +1,97 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.shenyu.admin.mapper; + +import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; +import org.apache.shenyu.admin.model.entity.ScalePolicyDO; +import org.apache.shenyu.admin.validation.ExistProvider; + +import java.io.Serializable; +import java.util.List; + +/** + * ScalePolicy Mapper. + */ +@Mapper +public interface ScalePolicyMapper extends ExistProvider { + + /** + * scale policy existed. + * + * @param id id + * @return existed + */ + @Override + Boolean existed(@Param("id") Serializable id); + + /** + * deleteByPrimaryKey. + * + * @param id id + * @return int + */ + int deleteByPrimaryKey(String id); + + /** + * insert. + * + * @param row row + * @return int + */ + int insert(ScalePolicyDO row); + + /** + * insertSelective. + * + * @param row row + * @return int + */ + int insertSelective(ScalePolicyDO row); + + /** + * selectByPrimaryKey. + * + * @param id id + * @return ScalePolicyDO + */ + ScalePolicyDO selectByPrimaryKey(String id); + + /** + * updateByPrimaryKeySelective. + * + * @param row row + * @return int + */ + int updateByPrimaryKeySelective(ScalePolicyDO row); + + /** + * updateByPrimaryKey. + * + * @param row row + * @return int + */ + int updateByPrimaryKey(ScalePolicyDO row); + + /** + * select all. + * + * @return List + */ + List selectAll(); +} diff --git a/shenyu-admin/src/main/java/org/apache/shenyu/admin/mapper/ScaleRuleMapper.java b/shenyu-admin/src/main/java/org/apache/shenyu/admin/mapper/ScaleRuleMapper.java new file mode 100644 index 000000000000..68902358ad93 --- /dev/null +++ b/shenyu-admin/src/main/java/org/apache/shenyu/admin/mapper/ScaleRuleMapper.java @@ -0,0 +1,119 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.shenyu.admin.mapper; + +import java.io.Serializable; +import java.util.List; + +import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; +import org.apache.shenyu.admin.model.entity.ScaleRuleDO; +import org.apache.shenyu.admin.model.query.ScaleRuleQuery; +import org.apache.shenyu.admin.validation.ExistProvider; + +@Mapper +public interface ScaleRuleMapper extends ExistProvider { + + /** + * scale rule existed. + * + * @param id id + * @return Boolean + */ + @Override + Boolean existed(@Param("id") Serializable id); + + /** + * count by example. + * + * @param scaleRuleQuery scaleRuleQuery + * @return long + */ + long countByQuery(ScaleRuleQuery scaleRuleQuery); + + /** + * delete by id. + * + * @param id id + * @return int + */ + int deleteByPrimaryKey(String id); + + /** + * delete. + * + * @param ids ids + * @return int + */ + int delete(List ids); + + /** + * insert. + * + * @param row row + * @return int + */ + int insert(ScaleRuleDO row); + + /** + * insertSelective. + * + * @param row row + * @return int + */ + int insertSelective(ScaleRuleDO row); + + /** + * selectByQuery. + * + * @param scaleRuleQuery scaleRuleQuery + * @return ScaleRuleDO> + */ + List selectByQuery(ScaleRuleQuery scaleRuleQuery); + + /** + * selectByPrimaryKey. + * + * @param id id + * @return ScaleRuleDO + */ + ScaleRuleDO selectByPrimaryKey(String id); + + /** + * updateByPrimaryKeySelective. + * + * @param row row + * @return int + */ + int updateByPrimaryKeySelective(ScaleRuleDO row); + + /** + * updateByPrimaryKey. + * + * @param row row + * @return int + */ + int updateByPrimaryKey(ScaleRuleDO row); + + /** + * select all. + * + * @return List + */ + List selectAll(); +} diff --git a/shenyu-admin/src/main/java/org/apache/shenyu/admin/model/dto/ScalePolicyDTO.java b/shenyu-admin/src/main/java/org/apache/shenyu/admin/model/dto/ScalePolicyDTO.java new file mode 100644 index 000000000000..0ee3bdfcdf0b --- /dev/null +++ b/shenyu-admin/src/main/java/org/apache/shenyu/admin/model/dto/ScalePolicyDTO.java @@ -0,0 +1,324 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.shenyu.admin.model.dto; + +import jakarta.validation.constraints.NotNull; +import org.apache.shenyu.admin.mapper.ScalePolicyMapper; +import org.apache.shenyu.admin.validation.annotation.Existed; + +import java.io.Serializable; +import java.time.LocalDateTime; +import java.util.Objects; + +/** + * this is the scale policy from by web front. + */ +public class ScalePolicyDTO implements Serializable { + + private static final long serialVersionUID = 3319087894871820638L; + + + /** + * primary key id. + */ + @Existed(provider = ScalePolicyMapper.class, nullOfIgnore = true, message = "scale policy is not existed") + private String id; + + /** + * sort. + */ + @NotNull + private Integer sort; + + /** + * status 1:enable 0:disable. + */ + @NotNull + private Integer status; + + /** + * number of bootstrap. + */ + private Integer num; + + /** + * begin time. + */ + private LocalDateTime beginTime; + + /** + * end time. + */ + private LocalDateTime endTime; + + public ScalePolicyDTO() { + } + + public ScalePolicyDTO(final String id, + final Integer sort, + final Integer status, + final Integer num, + final LocalDateTime beginTime, + final LocalDateTime endTime) { + this.id = id; + this.sort = sort; + this.status = status; + this.num = num; + this.beginTime = beginTime; + this.endTime = endTime; + } + + /** + * Gets the value of id. + * + * @return the value of id + */ + public String getId() { + return id; + } + + /** + * Sets the id. + * + * @param id id + */ + public void setId(final String id) { + this.id = id; + } + + /** + * Gets the value of sort. + * + * @return the value of sort + */ + public Integer getSort() { + return sort; + } + + /** + * Sets the sort. + * + * @param sort sort + */ + public void setSort(final Integer sort) { + this.sort = sort; + } + + /** + * Gets the value of status. + * + * @return the value of status + */ + public Integer getStatus() { + return status; + } + + /** + * Sets the status. + * + * @param status status + */ + public void setStatus(final Integer status) { + this.status = status; + } + + /** + * Gets the value of num. + * + * @return the value of num + */ + public Integer getNum() { + return num; + } + + /** + * Sets the num. + * + * @param num num + */ + public void setNum(final Integer num) { + this.num = num; + } + + /** + * Gets the value of beginTime. + * + * @return the value of beginTime + */ + public LocalDateTime getBeginTime() { + return beginTime; + } + + /** + * Sets the beginTime. + * + * @param beginTime beginTime + */ + public void setBeginTime(final LocalDateTime beginTime) { + this.beginTime = beginTime; + } + + /** + * Gets the value of endTime. + * + * @return the value of endTime + */ + public LocalDateTime getEndTime() { + return endTime; + } + + /** + * Sets the endTime. + * + * @param endTime endTime + */ + public void setEndTime(final LocalDateTime endTime) { + this.endTime = endTime; + } + + /** + * builder method. + * + * @return builder object. + */ + public static ScalePolicyDTO.ScalePolicyDTOBuilder builder() { + return new ScalePolicyDTO.ScalePolicyDTOBuilder(); + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + ScalePolicyDTO that = (ScalePolicyDTO) o; + return Objects.equals(id, that.id) + && Objects.equals(sort, that.sort) + && Objects.equals(status, that.status) + && Objects.equals(num, that.num) + && Objects.equals(beginTime, that.beginTime) + && Objects.equals(endTime, that.endTime); + } + + @Override + public int hashCode() { + return Objects.hash(id, sort, status, num, beginTime, endTime); + } + + public static final class ScalePolicyDTOBuilder { + + private String id; + + private Integer sort; + + private Integer status; + + private Integer num; + + private LocalDateTime beginTime; + + private LocalDateTime endTime; + + private ScalePolicyDTOBuilder() { + } + + /** + * id. + * + * @param id primary key + * @return ScalePolicyDTOBuilder + */ + public ScalePolicyDTOBuilder id(final String id) { + this.id = id; + return this; + } + + /** + * sort. + * + * @param sort sort + * @return ScalePolicyDTOBuilder + */ + public ScalePolicyDTOBuilder sort(final Integer sort) { + this.sort = sort; + return this; + } + + /** + * status. + * + * @param status status + * @return ScalePolicyDTOBuilder + */ + public ScalePolicyDTOBuilder status(final Integer status) { + this.status = status; + return this; + } + + /** + * num. + * + * @param num num + * @return ScalePolicyDTOBuilder + */ + public ScalePolicyDTOBuilder num(final Integer num) { + this.num = num; + return this; + } + + /** + * beginTime. + * + * @param beginTime beginTime + * @return ScalePolicyDTOBuilder + */ + public ScalePolicyDTOBuilder beginTime(final LocalDateTime beginTime) { + this.beginTime = beginTime; + return this; + } + + /** + * endTime. + * + * @param endTime endTime + * @return ScalePolicyDTOBuilder + */ + public ScalePolicyDTOBuilder endTime(final LocalDateTime endTime) { + this.endTime = endTime; + return this; + } + + /** + * build. + * + * @return ScalePolicyDTO + */ + public ScalePolicyDTO build() { + ScalePolicyDTO scalePolicyDTO = new ScalePolicyDTO(); + scalePolicyDTO.setId(id); + scalePolicyDTO.setSort(sort); + scalePolicyDTO.setStatus(status); + scalePolicyDTO.setNum(num); + scalePolicyDTO.setBeginTime(beginTime); + scalePolicyDTO.setEndTime(endTime); + return scalePolicyDTO; + } + } +} diff --git a/shenyu-admin/src/main/java/org/apache/shenyu/admin/model/dto/ScaleRuleDTO.java b/shenyu-admin/src/main/java/org/apache/shenyu/admin/model/dto/ScaleRuleDTO.java new file mode 100644 index 000000000000..27a48d6b616f --- /dev/null +++ b/shenyu-admin/src/main/java/org/apache/shenyu/admin/model/dto/ScaleRuleDTO.java @@ -0,0 +1,365 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.shenyu.admin.model.dto; + +import jakarta.validation.constraints.NotBlank; +import jakarta.validation.constraints.NotNull; +import org.apache.shenyu.admin.mapper.ScaleRuleMapper; +import org.apache.shenyu.admin.validation.annotation.Existed; + +import java.io.Serializable; +import java.util.Objects; + +/** + * this is the scale rule from by web front. + */ +public class ScaleRuleDTO implements Serializable { + + private static final long serialVersionUID = 7696616914460256129L; + + /** + * primary key id. + */ + @Existed(provider = ScaleRuleMapper.class, nullOfIgnore = true, message = "scale rule is not existed") + private String id; + + /** + * metric name. + */ + @NotBlank + private String metricName; + + /** + * type 0:shenyu 1:k8s 2:others. + */ + @NotNull + private Integer type; + + /** + * sort. + */ + @NotNull + private Integer sort; + + /** + * status 1:enable 0:disable. + */ + @NotNull + private Integer status; + + /** + * minimum of metric. + */ + private String minimum; + + /** + * maximum of metric. + */ + private String maximum; + + public ScaleRuleDTO() { + } + + public ScaleRuleDTO(final String id, + @NotBlank final String metricName, + @NotNull final Integer type, + @NotNull final Integer sort, + @NotNull final Integer status, + final String minimum, + final String maximum) { + this.id = id; + this.metricName = metricName; + this.type = type; + this.sort = sort; + this.status = status; + this.minimum = minimum; + this.maximum = maximum; + } + + /** + * Gets the value of id. + * + * @return the value of id + */ + public String getId() { + return id; + } + + /** + * Sets the id. + * + * @param id id + */ + public void setId(final String id) { + this.id = id; + } + + /** + * Gets the value of metricName. + * + * @return the value of metricName + */ + public String getMetricName() { + return metricName; + } + + /** + * Sets the metricName. + * + * @param metricName metricName + */ + public void setMetricName(final String metricName) { + this.metricName = metricName; + } + + /** + * Gets the value of type. + * + * @return the value of type + */ + public Integer getType() { + return type; + } + + /** + * Sets the type. + * + * @param type type + */ + public void setType(final Integer type) { + this.type = type; + } + + /** + * Gets the value of sort. + * + * @return the value of sort + */ + public Integer getSort() { + return sort; + } + + /** + * Sets the sort. + * + * @param sort sort + */ + public void setSort(final Integer sort) { + this.sort = sort; + } + + /** + * Gets the value of status. + * + * @return the value of status + */ + public Integer getStatus() { + return status; + } + + /** + * Sets the status. + * + * @param status status + */ + public void setStatus(final Integer status) { + this.status = status; + } + + /** + * Gets the value of minimum. + * + * @return the value of minimum + */ + public String getMinimum() { + return minimum; + } + + /** + * Sets the minimum. + * + * @param minimum minimum + */ + public void setMinimum(final String minimum) { + this.minimum = minimum; + } + + /** + * Gets the value of maximum. + * + * @return the value of maximum + */ + public String getMaximum() { + return maximum; + } + + /** + * Sets the maximum. + * + * @param maximum maximum + */ + public void setMaximum(final String maximum) { + this.maximum = maximum; + } + + /** + * builder. + * + * @return ScaleRuleDTOBuilder + */ + public static ScaleRuleDTO.ScaleRuleDTOBuilder builder() { + return new ScaleRuleDTO.ScaleRuleDTOBuilder(); + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + ScaleRuleDTO that = (ScaleRuleDTO) o; + return Objects.equals(id, that.id) + && Objects.equals(metricName, that.metricName) + && Objects.equals(type, that.type) + && Objects.equals(sort, that.sort) + && Objects.equals(status, that.status) + && Objects.equals(minimum, that.minimum) + && Objects.equals(maximum, that.maximum); + } + + @Override + public int hashCode() { + return Objects.hash(id, metricName, type, sort, status, minimum, maximum); + } + + public static final class ScaleRuleDTOBuilder { + + private String id; + + private String metricName; + + private Integer type; + + private Integer sort; + + private Integer status; + + private String minimum; + + private String maximum; + + private ScaleRuleDTOBuilder() { + } + + /** + * id. + * + * @param id id + * @return ScaleRuleDTOBuilder + */ + public ScaleRuleDTOBuilder id(final String id) { + this.id = id; + return this; + } + + /** + * metricName. + * + * @param metricName metricName + * @return ScaleRuleDTOBuilder + */ + public ScaleRuleDTOBuilder metricName(final String metricName) { + this.metricName = metricName; + return this; + } + + /** + * type. + * + * @param type type + * @return ScaleRuleDTOBuilder + */ + public ScaleRuleDTOBuilder type(final Integer type) { + this.type = type; + return this; + } + + /** + * sort. + * + * @param sort sort + * @return ScaleRuleDTOBuilder + */ + public ScaleRuleDTOBuilder sort(final Integer sort) { + this.sort = sort; + return this; + } + + /** + * status. + * + * @param status status + * @return ScaleRuleDTOBuilder + */ + public ScaleRuleDTOBuilder status(final Integer status) { + this.status = status; + return this; + } + + /** + * minimum. + * + * @param minimum minimum + * @return ScaleRuleDTOBuilder + */ + public ScaleRuleDTOBuilder minimum(final String minimum) { + this.minimum = minimum; + return this; + } + + /** + * maximum. + * + * @param maximum maximum + * @return ScaleRuleDTOBuilder + */ + public ScaleRuleDTOBuilder maximum(final String maximum) { + this.maximum = maximum; + return this; + } + + /** + * build. + * + * @return ScaleRuleDTO + */ + public ScaleRuleDTO build() { + ScaleRuleDTO scaleRuleDTO = new ScaleRuleDTO(); + scaleRuleDTO.setId(id); + scaleRuleDTO.setMetricName(metricName); + scaleRuleDTO.setType(type); + scaleRuleDTO.setSort(sort); + scaleRuleDTO.setStatus(status); + scaleRuleDTO.setMinimum(minimum); + scaleRuleDTO.setMaximum(maximum); + return scaleRuleDTO; + } + } +} diff --git a/shenyu-admin/src/main/java/org/apache/shenyu/admin/model/entity/ScaleHistoryDO.java b/shenyu-admin/src/main/java/org/apache/shenyu/admin/model/entity/ScaleHistoryDO.java new file mode 100644 index 000000000000..5930ebda4837 --- /dev/null +++ b/shenyu-admin/src/main/java/org/apache/shenyu/admin/model/entity/ScaleHistoryDO.java @@ -0,0 +1,277 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.shenyu.admin.model.entity; + +import java.sql.Timestamp; +import java.util.Date; +import java.util.Objects; + +/** + * ScaleHistoryDO. + */ +public final class ScaleHistoryDO extends BaseDO { + + private static final long serialVersionUID = 9073404091200662252L; + + /** + * primary key. + */ + private String id; + + /** + * config id. + */ + private Integer configId; + + /** + * number of bootstrap. + */ + private Integer num; + + /** + * action. + */ + private Integer action; + + /** + * message. + */ + private String msg; + + /** + * create time. + */ + private Date dateCreated; + + /** + * update time. + */ + private Date dateUpdated; + + public ScaleHistoryDO() { + } + + public ScaleHistoryDO(final Integer configId, final Integer num, final Integer action, final String msg) { + this.configId = configId; + this.num = num; + this.action = action; + this.msg = msg; + } + + /** + * Gets the value of configId. + * + * @return the value of configId + */ + public Integer getConfigId() { + return configId; + } + + /** + * Sets the configId. + * + * @param configId configId + */ + public void setConfigId(final Integer configId) { + this.configId = configId; + } + + /** + * Gets the value of num. + * + * @return the value of num + */ + public Integer getNum() { + return num; + } + + /** + * Sets the num. + * + * @param num num + */ + public void setNum(final Integer num) { + this.num = num; + } + + /** + * Gets the value of action. + * + * @return the value of action + */ + public Integer getAction() { + return action; + } + + /** + * Sets the action. + * + * @param action action + */ + public void setAction(final Integer action) { + this.action = action; + } + + /** + * Gets the value of msg. + * + * @return the value of msg + */ + public String getMsg() { + return msg; + } + + /** + * Sets the msg. + * + * @param msg msg + */ + public void setMsg(final String msg) { + this.msg = msg; + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + if (!super.equals(o)) { + return false; + } + ScaleHistoryDO that = (ScaleHistoryDO) o; + return Objects.equals(configId, that.configId) && Objects.equals(num, that.num) && Objects.equals(action, that.action) && Objects.equals(msg, that.msg); + } + + @Override + public int hashCode() { + return Objects.hash(super.hashCode(), configId, num, action, msg); + } + + public static final class ScaleHistoryDOBuilder { + + private String id; + + private Timestamp dateCreated; + + private Integer configId; + + private Integer num; + + private Integer action; + + private String msg; + + private Timestamp dateUpdated; + + private ScaleHistoryDOBuilder() { + } + + /** + * id. + * + * @param id id + * @return ScaleHistoryDOBuilder + */ + public ScaleHistoryDOBuilder id(final String id) { + this.id = id; + return this; + } + + /** + * dateCreated. + * + * @param dateCreated dateCreated + * @return ScaleHistoryDOBuilder + */ + public ScaleHistoryDOBuilder dateCreated(final Timestamp dateCreated) { + this.dateCreated = dateCreated; + return this; + } + + /** + * configId. + * + * @param configId configId + * @return ScaleHistoryDOBuilder + */ + public ScaleHistoryDOBuilder configId(final Integer configId) { + this.configId = configId; + return this; + } + + /** + * num. + * + * @param num num + * @return ScaleHistoryDOBuilder + */ + public ScaleHistoryDOBuilder num(final Integer num) { + this.num = num; + return this; + } + + /** + * action. + * + * @param action action + * @return ScaleHistoryDOBuilder + */ + public ScaleHistoryDOBuilder action(final Integer action) { + this.action = action; + return this; + } + + /** + * msg. + * + * @param msg msg + * @return ScaleHistoryDOBuilder + */ + public ScaleHistoryDOBuilder msg(final String msg) { + this.msg = msg; + return this; + } + + /** + * dateUpdated. + * + * @param dateUpdated dateUpdated + * @return ScaleHistoryDOBuilder + */ + public ScaleHistoryDOBuilder dateUpdated(final Timestamp dateUpdated) { + this.dateUpdated = dateUpdated; + return this; + } + + /** + * build. + * + * @return ScaleHistoryDO + */ + public ScaleHistoryDO build() { + ScaleHistoryDO scaleHistoryDO = new ScaleHistoryDO(configId, num, action, msg); + scaleHistoryDO.setId(id); + scaleHistoryDO.setDateCreated(dateCreated); + scaleHistoryDO.setDateUpdated(dateUpdated); + return scaleHistoryDO; + } + } +} diff --git a/shenyu-admin/src/main/java/org/apache/shenyu/admin/model/entity/ScalePolicyDO.java b/shenyu-admin/src/main/java/org/apache/shenyu/admin/model/entity/ScalePolicyDO.java new file mode 100644 index 000000000000..5ddfdbf6cb60 --- /dev/null +++ b/shenyu-admin/src/main/java/org/apache/shenyu/admin/model/entity/ScalePolicyDO.java @@ -0,0 +1,385 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.shenyu.admin.model.entity; + +import org.apache.commons.lang3.StringUtils; +import org.apache.shenyu.admin.model.dto.ScalePolicyDTO; +import org.apache.shenyu.common.utils.DateUtils; +import org.apache.shenyu.common.utils.UUIDUtils; + +import java.sql.Timestamp; +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.Date; +import java.util.Objects; +import java.util.Optional; + +/** + * Table: scale_policy. + */ +public final class ScalePolicyDO extends BaseDO { + + private static final long serialVersionUID = -6895279885108899135L; + + /** + * Column: sort. + * Type: INT. + * Remark: sort. + */ + private Integer sort; + + /** + * Column: status. + * Type: INT. + * Remark: status 1:enable 0:disable. + */ + private Integer status; + + /** + * Column: num. + * Type: INT. + * Remark: number of bootstrap. + */ + private Integer num; + + /** + * Column: begin_time. + * Type: DATETIME. + * Remark: begin time. + */ + private Date beginTime; + + /** + * Column: end_time. + * Type: DATETIME. + * Remark: end time. + */ + private Date endTime; + + /** + * Column: date_created. + * Type: TIMESTAMP. + * Default value: CURRENT_TIMESTAMP(3). + * Remark: create time. + */ + private Date dateCreated; + + /** + * Column: date_updated. + * Type: TIMESTAMP. + * Default value: CURRENT_TIMESTAMP(3). + * Remark: update time. + */ + private Date dateUpdated; + + public ScalePolicyDO() { + } + + public ScalePolicyDO(final Integer sort, final Integer status, final Integer num, final Date beginTime, final Date endTime) { + this.sort = sort; + this.status = status; + this.num = num; + this.beginTime = beginTime; + this.endTime = endTime; + } + + /** + * Gets the value of sort. + * + * @return the value of sort + */ + public Integer getSort() { + return sort; + } + + /** + * Sets the sort. + * + * @param sort sort + */ + public void setSort(final Integer sort) { + this.sort = sort; + } + + /** + * Gets the value of status. + * + * @return the value of status + */ + public Integer getStatus() { + return status; + } + + /** + * Sets the status. + * + * @param status status + */ + public void setStatus(final Integer status) { + this.status = status; + } + + /** + * Gets the value of num. + * + * @return the value of num + */ + public Integer getNum() { + return num; + } + + /** + * Sets the num. + * + * @param num num + */ + public void setNum(final Integer num) { + this.num = num; + } + + /** + * Gets the value of beginTime. + * + * @return the value of beginTime + */ + public Date getBeginTime() { + return beginTime; + } + + /** + * Sets the beginTime. + * + * @param beginTime beginTime + */ + public void setBeginTime(final Date beginTime) { + this.beginTime = beginTime; + } + + /** + * Gets the value of endTime. + * + * @return the value of endTime + */ + public Date getEndTime() { + return endTime; + } + + /** + * Sets the endTime. + * + * @param endTime endTime + */ + public void setEndTime(final Date endTime) { + this.endTime = endTime; + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + if (!super.equals(o)) { + return false; + } + ScalePolicyDO that = (ScalePolicyDO) o; + return Objects.equals(sort, that.sort) + && Objects.equals(status, that.status) + && Objects.equals(num, that.num) + && Objects.equals(beginTime, that.beginTime) + && Objects.equals(endTime, that.endTime); + } + + @Override + public int hashCode() { + return Objects.hash(super.hashCode(), sort, status, num, beginTime, endTime); + } + + /** + * builder. + * + * @return ScalePolicyDOBuilder + */ + public static ScalePolicyDO.ScalePolicyDOBuilder builder() { + return new ScalePolicyDO.ScalePolicyDOBuilder(); + } + + /** + * buildScalePolicyDO. + * + * @param scalePolicyDTO scalePolicyDTO + * @return ScalePolicyDO + */ + public static ScalePolicyDO buildScalePolicyDO(final ScalePolicyDTO scalePolicyDTO) { + return Optional.ofNullable(scalePolicyDTO).map(item -> { + Timestamp currentTime = new Timestamp(System.currentTimeMillis()); + try { + ScalePolicyDO scalePolicyDO = + ScalePolicyDO.builder() + .sort(item.getSort()) + .status(item.getStatus()) + .num(item.getNum()) + .beginTime(DateUtils.isValidDate(DateUtils.localDateTimeToString(item.getBeginTime())) + ? new SimpleDateFormat("yyyy-MM-dd").parse(DateUtils.localDateTimeToString(item.getBeginTime())) : null) + .endTime(DateUtils.isValidDate(DateUtils.localDateTimeToString(item.getEndTime())) + ? new SimpleDateFormat("yyyy-MM-dd").parse(DateUtils.localDateTimeToString(item.getEndTime())) : null) + .dateUpdated(currentTime) + .build(); + if (StringUtils.isEmpty(item.getId())) { + scalePolicyDO.setId(UUIDUtils.getInstance().generateShortUuid()); + scalePolicyDO.setDateCreated(currentTime); + } else { + scalePolicyDO.setId(item.getId()); + } + return scalePolicyDO; + } catch (ParseException e) { + throw new RuntimeException(e); + } + }).orElse(null); + } + + public static final class ScalePolicyDOBuilder { + + private String id; + + private Integer sort; + + private Integer status; + + private Integer num; + + private Date beginTime; + + private Date endTime; + + private Timestamp dateCreated; + + private Timestamp dateUpdated; + + private ScalePolicyDOBuilder() { + } + + /** + * id. + * + * @param id id + * @return ScalePolicyDOBuilder + */ + public ScalePolicyDOBuilder id(final String id) { + this.id = id; + return this; + } + + /** + * sort. + * + * @param sort sort + * @return ScalePolicyDOBuilder + */ + public ScalePolicyDOBuilder sort(final Integer sort) { + this.sort = sort; + return this; + } + + /** + * status. + * + * @param status status + * @return ScalePolicyDOBuilder + */ + public ScalePolicyDOBuilder status(final Integer status) { + this.status = status; + return this; + } + + /** + * num. + * + * @param num num + * @return ScalePolicyDOBuilder + */ + public ScalePolicyDOBuilder num(final Integer num) { + this.num = num; + return this; + } + + /** + * beginTime. + * + * @param beginTime beginTime + * @return ScalePolicyDOBuilder + */ + public ScalePolicyDOBuilder beginTime(final Date beginTime) { + this.beginTime = beginTime; + return this; + } + + /** + * endTime. + * + * @param endTime endTime + * @return ScalePolicyDOBuilder + */ + public ScalePolicyDOBuilder endTime(final Date endTime) { + this.endTime = endTime; + return this; + } + + /** + * dateCreated. + * + * @param dateCreated dateCreated + * @return ScalePolicyDOBuilder + */ + public ScalePolicyDOBuilder dateCreated(final Timestamp dateCreated) { + this.dateCreated = dateCreated; + return this; + } + + /** + * dateUpdated. + * + * @param dateUpdated dateUpdated + * @return ScalePolicyDOBuilder + */ + public ScalePolicyDOBuilder dateUpdated(final Timestamp dateUpdated) { + this.dateUpdated = dateUpdated; + return this; + } + + /** + * build. + * + * @return ScalePolicyDO + */ + public ScalePolicyDO build() { + ScalePolicyDO scalePolicyDO = new ScalePolicyDO(); + scalePolicyDO.setId(id); + scalePolicyDO.setSort(sort); + scalePolicyDO.setStatus(status); + scalePolicyDO.setNum(num); + scalePolicyDO.setBeginTime(beginTime); + scalePolicyDO.setEndTime(endTime); + scalePolicyDO.setDateCreated(dateCreated); + scalePolicyDO.setDateUpdated(dateUpdated); + return scalePolicyDO; + } + } +} diff --git a/shenyu-admin/src/main/java/org/apache/shenyu/admin/model/entity/ScaleRuleDO.java b/shenyu-admin/src/main/java/org/apache/shenyu/admin/model/entity/ScaleRuleDO.java new file mode 100644 index 000000000000..86e546a03cac --- /dev/null +++ b/shenyu-admin/src/main/java/org/apache/shenyu/admin/model/entity/ScaleRuleDO.java @@ -0,0 +1,399 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.shenyu.admin.model.entity; + +import org.apache.commons.lang3.StringUtils; +import org.apache.shenyu.admin.model.dto.ScaleRuleDTO; +import org.apache.shenyu.common.utils.UUIDUtils; + +import java.sql.Timestamp; +import java.util.Objects; +import java.util.Optional; + +/** + * Table: scale_rule. + */ +public final class ScaleRuleDO extends BaseDO { + + private static final long serialVersionUID = 8778323510074951149L; + + /** + * Column: metric_name. + * Type: VARCHAR(128). + * Remark: metric name. + */ + private String metricName; + + /** + * Column: type. + * Type: INT. + * Remark: type 0:shenyu 1:k8s 2:others. + */ + private Integer type; + + /** + * Column: sort. + * Type: INT. + * Remark: sort. + */ + private Integer sort; + + /** + * Column: status. + * Type: INT. + * Remark: status 1:enable 0:disable. + */ + private Integer status; + + /** + * Column: minimum. + * Type: VARCHAR(128). + * Remark: minimum of metric. + */ + private String minimum; + + /** + * Column: maximum. + * Type: VARCHAR(128). + * Remark: maximum of metric. + */ + private String maximum; + + public ScaleRuleDO() { + } + + public ScaleRuleDO(final String metricName, final Integer type, final Integer sort, final Integer status, final String minimum, final String maximum) { + this.metricName = metricName; + this.type = type; + this.sort = sort; + this.status = status; + this.minimum = minimum; + this.maximum = maximum; + } + + /** + * Gets the value of metricName. + * + * @return the value of metricName + */ + public String getMetricName() { + return metricName; + } + + /** + * Sets the metricName. + * + * @param metricName metricName + */ + public void setMetricName(final String metricName) { + this.metricName = metricName; + } + + /** + * Gets the value of type. + * + * @return the value of type + */ + public Integer getType() { + return type; + } + + /** + * Sets the type. + * + * @param type type + */ + public void setType(final Integer type) { + this.type = type; + } + + /** + * Gets the value of sort. + * + * @return the value of sort + */ + public Integer getSort() { + return sort; + } + + /** + * Sets the sort. + * + * @param sort sort + */ + public void setSort(final Integer sort) { + this.sort = sort; + } + + /** + * Gets the value of status. + * + * @return the value of status + */ + public Integer getStatus() { + return status; + } + + /** + * Sets the status. + * + * @param status status + */ + public void setStatus(final Integer status) { + this.status = status; + } + + /** + * Gets the value of minimum. + * + * @return the value of minimum + */ + public String getMinimum() { + return minimum; + } + + /** + * Sets the minimum. + * + * @param minimum minimum + */ + public void setMinimum(final String minimum) { + this.minimum = minimum; + } + + /** + * Gets the value of maximum. + * + * @return the value of maximum + */ + public String getMaximum() { + return maximum; + } + + /** + * Sets the maximum. + * + * @param maximum maximum + */ + public void setMaximum(final String maximum) { + this.maximum = maximum; + } + + /** + * builder. + * + * @return ScaleRuleDOBuilder + */ + public static ScaleRuleDO.ScaleRuleDOBuilder builder() { + return new ScaleRuleDO.ScaleRuleDOBuilder(); + } + + /** + * build ScaleRuleDO. + * + * @param scaleRuleDTO scaleRuleDTO + * @return ScaleRuleDO + */ + public static ScaleRuleDO buildScaleRuleDO(final ScaleRuleDTO scaleRuleDTO) { + ScaleRuleDO scaleRuleDO = new ScaleRuleDO(); + if (StringUtils.isEmpty(scaleRuleDTO.getId())) { + scaleRuleDO.setId(UUIDUtils.getInstance().generateShortUuid()); + scaleRuleDO.setDateCreated(new Timestamp(System.currentTimeMillis())); + } else { + scaleRuleDO.setId(scaleRuleDTO.getId()); + } + return Optional.of(scaleRuleDTO).map(item -> { + Timestamp currentTime = new Timestamp(System.currentTimeMillis()); + scaleRuleDO.setMetricName(item.getMetricName()); + scaleRuleDO.setType(item.getType()); + scaleRuleDO.setSort(item.getSort()); + scaleRuleDO.setStatus(item.getStatus()); + scaleRuleDO.setMinimum(item.getMinimum()); + scaleRuleDO.setMaximum(item.getMaximum()); + scaleRuleDO.setDateUpdated(currentTime); + return scaleRuleDO; + }).orElse(null); + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + if (!super.equals(o)) { + return false; + } + ScaleRuleDO that = (ScaleRuleDO) o; + return Objects.equals(metricName, that.metricName) + && Objects.equals(type, that.type) + && Objects.equals(sort, that.sort) + && Objects.equals(status, that.status) + && Objects.equals(minimum, that.minimum) + && Objects.equals(maximum, that.maximum); + } + + @Override + public int hashCode() { + return Objects.hash(super.hashCode(), metricName, type, sort, status, minimum, maximum); + } + + public static final class ScaleRuleDOBuilder { + + private String id; + + private Timestamp dateCreated; + + private Timestamp dateUpdated; + + private String metricName; + + private Integer type; + + private Integer sort; + + private Integer status; + + private String minimum; + + private String maximum; + + private ScaleRuleDOBuilder() { + } + + /** + * metricName. + * + * @param metricName metricName + * @return ScaleRuleDOBuilder + */ + public ScaleRuleDOBuilder metricName(final String metricName) { + this.metricName = metricName; + return this; + } + + /** + * type. + * + * @param type type + * @return ScaleRuleDOBuilder + */ + public ScaleRuleDOBuilder type(final Integer type) { + this.type = type; + return this; + } + + /** + * sort. + * + * @param sort sort + * @return ScaleRuleDOBuilder + */ + public ScaleRuleDOBuilder sort(final Integer sort) { + this.sort = sort; + return this; + } + + /** + * status. + * + * @param status status + * @return ScaleRuleDOBuilder + */ + public ScaleRuleDOBuilder status(final Integer status) { + this.status = status; + return this; + } + + /** + * minimum. + * + * @param minimum minimum + * @return ScaleRuleDOBuilder + */ + public ScaleRuleDOBuilder minimum(final String minimum) { + this.minimum = minimum; + return this; + } + + /** + * maximum. + * + * @param maximum maximum + * @return ScaleRuleDOBuilder + */ + public ScaleRuleDOBuilder maximum(final String maximum) { + this.maximum = maximum; + return this; + } + + /** + * id. + * + * @param id id + * @return ScaleRuleDOBuilder + */ + public ScaleRuleDOBuilder id(final String id) { + this.id = id; + return this; + } + + /** + * dateCreated. + * + * @param dateCreated dateCreated + * @return ScaleRuleDOBuilder + */ + public ScaleRuleDOBuilder dateCreated(final Timestamp dateCreated) { + this.dateCreated = dateCreated; + return this; + } + + /** + * dateUpdated. + * + * @param dateUpdated dateUpdated + * @return ScaleRuleDOBuilder + */ + public ScaleRuleDOBuilder dateUpdated(final Timestamp dateUpdated) { + this.dateUpdated = dateUpdated; + return this; + } + + /** + * build. + * + * @return ScaleRuleDO + */ + public ScaleRuleDO build() { + ScaleRuleDO scaleRuleDO = new ScaleRuleDO(); + scaleRuleDO.setId(id); + scaleRuleDO.setDateCreated(dateCreated); + scaleRuleDO.setDateUpdated(dateUpdated); + scaleRuleDO.setMetricName(metricName); + scaleRuleDO.setType(type); + scaleRuleDO.setSort(sort); + scaleRuleDO.setStatus(status); + scaleRuleDO.setMinimum(minimum); + scaleRuleDO.setMaximum(maximum); + return scaleRuleDO; + } + } +} diff --git a/shenyu-admin/src/main/java/org/apache/shenyu/admin/model/query/ScaleRuleQuery.java b/shenyu-admin/src/main/java/org/apache/shenyu/admin/model/query/ScaleRuleQuery.java new file mode 100644 index 000000000000..b15e5d04a038 --- /dev/null +++ b/shenyu-admin/src/main/java/org/apache/shenyu/admin/model/query/ScaleRuleQuery.java @@ -0,0 +1,102 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.shenyu.admin.model.query; + +import org.apache.shenyu.admin.model.page.PageParameter; + +import java.io.Serializable; +import java.util.Objects; + +/** + * The scale rule query. + */ +public class ScaleRuleQuery implements Serializable { + + private static final long serialVersionUID = 8022510132462999321L; + + /** + * metric name. + */ + private String metricName; + + /** + * page parameter. + */ + private PageParameter pageParameter; + + public ScaleRuleQuery() { + } + + public ScaleRuleQuery(final String metricName, final PageParameter pageParameter) { + this.metricName = metricName; + this.pageParameter = pageParameter; + } + + /** + * Gets the value of metricName. + * + * @return the value of metricName + */ + public String getMetricName() { + return metricName; + } + + /** + * Sets the metricName. + * + * @param metricName metricName + */ + public void setMetricName(final String metricName) { + this.metricName = metricName; + } + + /** + * Gets the value of pageParameter. + * + * @return the value of pageParameter + */ + public PageParameter getPageParameter() { + return pageParameter; + } + + /** + * Sets the pageParameter. + * + * @param pageParameter pageParameter + */ + public void setPageParameter(final PageParameter pageParameter) { + this.pageParameter = pageParameter; + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + ScaleRuleQuery that = (ScaleRuleQuery) o; + return Objects.equals(metricName, that.metricName) && Objects.equals(pageParameter, that.pageParameter); + } + + @Override + public int hashCode() { + return Objects.hash(metricName, pageParameter); + } +} diff --git a/shenyu-admin/src/main/java/org/apache/shenyu/admin/model/vo/ScalePolicyVO.java b/shenyu-admin/src/main/java/org/apache/shenyu/admin/model/vo/ScalePolicyVO.java new file mode 100644 index 000000000000..2cd8079be31c --- /dev/null +++ b/shenyu-admin/src/main/java/org/apache/shenyu/admin/model/vo/ScalePolicyVO.java @@ -0,0 +1,298 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.shenyu.admin.model.vo; + +import org.apache.shenyu.admin.model.entity.ScalePolicyDO; +import org.apache.shenyu.common.utils.DateUtils; + +import java.io.Serializable; +import java.sql.Timestamp; +import java.util.Objects; +import java.util.Optional; + +/** + * this is scale policy view to web front. + */ +public class ScalePolicyVO implements Serializable { + + private static final long serialVersionUID = 7948061709049446961L; + + /** + * primary key id. + */ + private String id; + + /** + * sort. + */ + private Integer sort; + + /** + * status 1:enable 0:disable. + */ + private Integer status; + + /** + * number of bootstrap. + */ + private Integer num; + + /** + * begin time. + */ + private String beginTime; + + /** + * end time. + */ + private String endTime; + + /** + * create time. + */ + private String dateCreated; + + /** + * update time. + */ + private String dateUpdated; + + public ScalePolicyVO() { + } + + public ScalePolicyVO(final String id, + final Integer sort, + final Integer status, + final Integer num, + final String beginTime, + final String endTime, + final String dateCreated, + final String dateUpdated) { + this.id = id; + this.sort = sort; + this.status = status; + this.num = num; + this.beginTime = beginTime; + this.endTime = endTime; + this.dateCreated = dateCreated; + this.dateUpdated = dateUpdated; + } + + /** + * Gets the value of id. + * + * @return the value of id + */ + public String getId() { + return id; + } + + /** + * Sets the id. + * + * @param id id + */ + public void setId(final String id) { + this.id = id; + } + + /** + * Gets the value of sort. + * + * @return the value of sort + */ + public Integer getSort() { + return sort; + } + + /** + * Sets the sort. + * + * @param sort sort + */ + public void setSort(final Integer sort) { + this.sort = sort; + } + + /** + * Gets the value of status. + * + * @return the value of status + */ + public Integer getStatus() { + return status; + } + + /** + * Sets the status. + * + * @param status status + */ + public void setStatus(final Integer status) { + this.status = status; + } + + /** + * Gets the value of num. + * + * @return the value of num + */ + public Integer getNum() { + return num; + } + + /** + * Sets the num. + * + * @param num num + */ + public void setNum(final Integer num) { + this.num = num; + } + + /** + * Gets the value of beginTime. + * + * @return the value of beginTime + */ + public String getBeginTime() { + return beginTime; + } + + /** + * Sets the beginTime. + * + * @param beginTime beginTime + */ + public void setBeginTime(final String beginTime) { + this.beginTime = beginTime; + } + + /** + * Gets the value of endTime. + * + * @return the value of endTime + */ + public String getEndTime() { + return endTime; + } + + /** + * Sets the endTime. + * + * @param endTime endTime + */ + public void setEndTime(final String endTime) { + this.endTime = endTime; + } + + /** + * Gets the value of dateCreated. + * + * @return the value of dateCreated + */ + public String getDateCreated() { + return dateCreated; + } + + /** + * Sets the dateCreated. + * + * @param dateCreated dateCreated + */ + public void setDateCreated(final String dateCreated) { + this.dateCreated = dateCreated; + } + + /** + * Gets the value of dateUpdated. + * + * @return the value of dateUpdated + */ + public String getDateUpdated() { + return dateUpdated; + } + + /** + * Sets the dateUpdated. + * + * @param dateUpdated dateUpdated + */ + public void setDateUpdated(final String dateUpdated) { + this.dateUpdated = dateUpdated; + } + + /** + * buildScalePolicyVO. + * + * @param scalePolicyDO scalePolicyDO + * @return ScalePolicyVO + */ + public static ScalePolicyVO buildScalePolicyVO(final ScalePolicyDO scalePolicyDO) { + return Optional.ofNullable(scalePolicyDO) + .map(item -> { + String beginTime = item.getBeginTime() != null + ? DateUtils.localDateTimeToString(new Timestamp(item.getBeginTime().getTime()).toLocalDateTime()) : null; + String endTime = item.getEndTime() != null + ? DateUtils.localDateTimeToString(new Timestamp(item.getEndTime().getTime()).toLocalDateTime()) : null; + return new ScalePolicyVO(item.getId(), item.getSort(), item.getStatus(), item.getNum(), + beginTime, + endTime, + DateUtils.localDateTimeToString(item.getDateCreated().toLocalDateTime()), + DateUtils.localDateTimeToString(item.getDateUpdated().toLocalDateTime())); + }).orElse(null); + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + ScalePolicyVO that = (ScalePolicyVO) o; + return Objects.equals(id, that.id) + && Objects.equals(sort, that.sort) + && Objects.equals(status, that.status) + && Objects.equals(num, that.num) + && Objects.equals(beginTime, that.beginTime) + && Objects.equals(endTime, that.endTime) + && Objects.equals(dateCreated, that.dateCreated) + && Objects.equals(dateUpdated, that.dateUpdated); + } + + @Override + public int hashCode() { + return Objects.hash(id, sort, status, num, beginTime, endTime, dateCreated, dateUpdated); + } + + @Override + public String toString() { + return "ScalePolicyVO{" + + "id='" + id + '\'' + + ", sort=" + sort + + ", status=" + status + + ", num=" + num + + ", beginTime='" + beginTime + '\'' + + ", endTime='" + endTime + '\'' + + ", dateCreated='" + dateCreated + '\'' + + ", dateUpdated='" + dateUpdated + '\'' + + '}'; + } +} diff --git a/shenyu-admin/src/main/java/org/apache/shenyu/admin/model/vo/ScaleRuleVO.java b/shenyu-admin/src/main/java/org/apache/shenyu/admin/model/vo/ScaleRuleVO.java new file mode 100644 index 000000000000..798e0d84ad21 --- /dev/null +++ b/shenyu-admin/src/main/java/org/apache/shenyu/admin/model/vo/ScaleRuleVO.java @@ -0,0 +1,317 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.shenyu.admin.model.vo; + +import org.apache.shenyu.admin.model.entity.ScaleRuleDO; +import org.apache.shenyu.common.utils.DateUtils; + +import java.io.Serializable; +import java.util.Objects; +import java.util.Optional; + +/** + * this is scale rule view to web front. + */ +public class ScaleRuleVO implements Serializable { + + private static final long serialVersionUID = 5425558125437748538L; + + /** + * primary key id. + */ + private String id; + + /** + * metric name. + */ + private String metricName; + + /** + * type 0:shenyu 1:k8s 2:others. + */ + private Integer type; + + /** + * sort. + */ + private Integer sort; + + /** + * status 1:enable 0:disable. + */ + private Integer status; + + /** + * minimum of metric. + */ + private String minimum; + + /** + * maximum of metric. + */ + private String maximum; + + /** + * create time. + */ + private String dateCreated; + + /** + * update time. + */ + private String dateUpdated; + + public ScaleRuleVO() { + } + + public ScaleRuleVO(final String id, + final String metricName, + final Integer type, + final Integer sort, + final Integer status, + final String minimum, + final String maximum, + final String dateCreated, + final String dateUpdated) { + this.id = id; + this.metricName = metricName; + this.type = type; + this.sort = sort; + this.status = status; + this.minimum = minimum; + this.maximum = maximum; + this.dateCreated = dateCreated; + this.dateUpdated = dateUpdated; + } + + /** + * Gets the value of id. + * + * @return the value of id + */ + public String getId() { + return id; + } + + /** + * Sets the id. + * + * @param id id + */ + public void setId(final String id) { + this.id = id; + } + + /** + * Gets the value of metricName. + * + * @return the value of metricName + */ + public String getMetricName() { + return metricName; + } + + /** + * Sets the metricName. + * + * @param metricName metricName + */ + public void setMetricName(final String metricName) { + this.metricName = metricName; + } + + /** + * Gets the value of type. + * + * @return the value of type + */ + public Integer getType() { + return type; + } + + /** + * Sets the type. + * + * @param type type + */ + public void setType(final Integer type) { + this.type = type; + } + + /** + * Gets the value of sort. + * + * @return the value of sort + */ + public Integer getSort() { + return sort; + } + + /** + * Sets the sort. + * + * @param sort sort + */ + public void setSort(final Integer sort) { + this.sort = sort; + } + + /** + * Gets the value of status. + * + * @return the value of status + */ + public Integer getStatus() { + return status; + } + + /** + * Sets the status. + * + * @param status status + */ + public void setStatus(final Integer status) { + this.status = status; + } + + /** + * Gets the value of minimum. + * + * @return the value of minimum + */ + public String getMinimum() { + return minimum; + } + + /** + * Sets the minimum. + * + * @param minimum minimum + */ + public void setMinimum(final String minimum) { + this.minimum = minimum; + } + + /** + * Gets the value of maximum. + * + * @return the value of maximum + */ + public String getMaximum() { + return maximum; + } + + /** + * Sets the maximum. + * + * @param maximum maximum + */ + public void setMaximum(final String maximum) { + this.maximum = maximum; + } + + /** + * Gets the value of dateCreated. + * + * @return the value of dateCreated + */ + public String getDateCreated() { + return dateCreated; + } + + /** + * Sets the dateCreated. + * + * @param dateCreated dateCreated + */ + public void setDateCreated(final String dateCreated) { + this.dateCreated = dateCreated; + } + + /** + * Gets the value of dateUpdated. + * + * @return the value of dateUpdated + */ + public String getDateUpdated() { + return dateUpdated; + } + + /** + * Sets the dateUpdated. + * + * @param dateUpdated dateUpdated + */ + public void setDateUpdated(final String dateUpdated) { + this.dateUpdated = dateUpdated; + } + + /** + * build scaleRuleVO. + * + * @param scaleRuleDO {@linkplain ScaleRuleDO} + * @return {@linkplain ScaleRuleVO} + */ + public static ScaleRuleVO buildScaleRuleVO(final ScaleRuleDO scaleRuleDO) { + return Optional.ofNullable(scaleRuleDO) + .map(item -> new ScaleRuleVO(item.getId(), item.getMetricName(), item.getType(), + item.getSort(), item.getStatus(), item.getMinimum(), item.getMaximum(), + DateUtils.localDateTimeToString(item.getDateCreated().toLocalDateTime()), + DateUtils.localDateTimeToString(item.getDateUpdated().toLocalDateTime()))).orElse(null); + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + ScaleRuleVO that = (ScaleRuleVO) o; + return Objects.equals(id, that.id) + && Objects.equals(metricName, that.metricName) + && Objects.equals(type, that.type) + && Objects.equals(sort, that.sort) + && Objects.equals(status, that.status) + && Objects.equals(minimum, that.minimum) + && Objects.equals(maximum, that.maximum) + && Objects.equals(dateCreated, that.dateCreated) + && Objects.equals(dateUpdated, that.dateUpdated); + } + + @Override + public int hashCode() { + return Objects.hash(id, metricName, type, sort, status, minimum, maximum, dateCreated, dateUpdated); + } + + @Override + public String toString() { + return "ScaleRuleVO{" + + "id='" + id + '\'' + + ", metricName='" + metricName + '\'' + + ", type=" + type + + ", sort=" + sort + + ", status=" + status + + ", minimum='" + minimum + '\'' + + ", maximum='" + maximum + '\'' + + ", dateCreated='" + dateCreated + '\'' + + ", dateUpdated='" + dateUpdated + '\'' + + '}'; + } +} diff --git a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/ScalePolicyService.java b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/ScalePolicyService.java new file mode 100644 index 000000000000..356e4ae75be6 --- /dev/null +++ b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/ScalePolicyService.java @@ -0,0 +1,53 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.shenyu.admin.service; + +import org.apache.shenyu.admin.model.dto.ScalePolicyDTO; +import org.apache.shenyu.admin.model.vo.ScalePolicyVO; + +import java.util.List; + +/** + * this is the scale policy service. + */ +public interface ScalePolicyService { + + /** + * select all. + * + * @return List + */ + List selectAll(); + + /** + * find scale policy by id. + * + * @param id primary key + * @return {@linkplain ScalePolicyVO} + */ + ScalePolicyVO findById(String id); + + /** + * create or update scale policy. + * + * @param scalePolicyDTO {@linkplain ScalePolicyDTO} + * @return rows int + */ + int update(ScalePolicyDTO scalePolicyDTO); + +} diff --git a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/ScaleRuleService.java b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/ScaleRuleService.java new file mode 100644 index 000000000000..6fc039bb1066 --- /dev/null +++ b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/ScaleRuleService.java @@ -0,0 +1,89 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.shenyu.admin.service; + +import org.apache.commons.lang3.StringUtils; +import org.apache.shenyu.admin.model.dto.ScaleRuleDTO; +import org.apache.shenyu.admin.model.page.CommonPager; +import org.apache.shenyu.admin.model.query.ScaleRuleQuery; +import org.apache.shenyu.admin.model.vo.ScaleRuleVO; + +import java.util.List; + +/** + * this is scale rule service. + */ +public interface ScaleRuleService { + + /** + * selectAll. + * + * @return java.util.List + */ + List selectAll(); + + /** + * find page of scale rule by query. + * + * @param scaleRuleQuery {@linkplain ScaleRuleQuery} + * @return {@linkplain CommonPager} + */ + CommonPager listByPage(ScaleRuleQuery scaleRuleQuery); + + /** + * find scale rule by id. + * + * @param id primary key + * @return {@linkplain ScaleRuleVO} + */ + ScaleRuleVO findById(String id); + + /** + * create or update rule. + * + * @param scaleRuleDTO {@linkplain ScaleRuleDTO} + * @return rows int + */ + default int createOrUpdate(ScaleRuleDTO scaleRuleDTO) { + return StringUtils.isBlank(scaleRuleDTO.getId()) ? create(scaleRuleDTO) : update(scaleRuleDTO); + } + + /** + * create or update rule. + * + * @param scaleRuleDTO {@linkplain ScaleRuleDTO} + * @return rows int + */ + int create(ScaleRuleDTO scaleRuleDTO); + + /** + * create or update rule. + * + * @param scaleRuleDTO {@linkplain ScaleRuleDTO} + * @return rows int + */ + int update(ScaleRuleDTO scaleRuleDTO); + + /** + * delete rules. + * + * @param ids primary key + * @return rows int + */ + int delete(List ids); +} diff --git a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/ScalePolicyServiceImpl.java b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/ScalePolicyServiceImpl.java new file mode 100644 index 000000000000..838a7d86a5db --- /dev/null +++ b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/ScalePolicyServiceImpl.java @@ -0,0 +1,74 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.shenyu.admin.service.impl; + +import org.apache.shenyu.admin.mapper.ScalePolicyMapper; +import org.apache.shenyu.admin.model.dto.ScalePolicyDTO; +import org.apache.shenyu.admin.model.entity.ScalePolicyDO; +import org.apache.shenyu.admin.model.vo.ScalePolicyVO; +import org.apache.shenyu.admin.service.ScalePolicyService; +import org.apache.shenyu.common.utils.ListUtil; +import org.springframework.stereotype.Service; + +import java.util.List; + +/** + * Implementation of ScalePolicyService. + */ +@Service +public class ScalePolicyServiceImpl implements ScalePolicyService { + + private final ScalePolicyMapper scalePolicyMapper; + + public ScalePolicyServiceImpl(final ScalePolicyMapper scalePolicyMapper) { + this.scalePolicyMapper = scalePolicyMapper; + } + + /** + * select all. + * + * @return List + */ + @Override + public List selectAll() { + return ListUtil.map(scalePolicyMapper.selectAll(), ScalePolicyVO::buildScalePolicyVO); + } + + /** + * find scale policy by id. + * + * @param id primary key + * @return {@linkplain ScalePolicyVO} + */ + @Override + public ScalePolicyVO findById(final String id) { + return ScalePolicyVO.buildScalePolicyVO(scalePolicyMapper.selectByPrimaryKey(id)); + } + + /** + * create or update scale policy. + * + * @param scalePolicyDTO {@linkplain ScalePolicyDTO} + * @return rows int + */ + @Override + public int update(final ScalePolicyDTO scalePolicyDTO) { + final ScalePolicyDO scalePolicy = ScalePolicyDO.buildScalePolicyDO(scalePolicyDTO); + return scalePolicyMapper.updateByPrimaryKey(scalePolicy); + } +} diff --git a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/ScaleRuleServiceImpl.java b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/ScaleRuleServiceImpl.java new file mode 100644 index 000000000000..bacbc331b40b --- /dev/null +++ b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/ScaleRuleServiceImpl.java @@ -0,0 +1,131 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.shenyu.admin.service.impl; + +import org.apache.shenyu.admin.aspect.annotation.Pageable; +import org.apache.shenyu.admin.mapper.ScaleRuleMapper; +import org.apache.shenyu.admin.model.dto.ScaleRuleDTO; +import org.apache.shenyu.admin.model.entity.ScaleRuleDO; +import org.apache.shenyu.admin.model.page.CommonPager; +import org.apache.shenyu.admin.model.page.PageResultUtils; +import org.apache.shenyu.admin.model.query.ScaleRuleQuery; +import org.apache.shenyu.admin.model.vo.ScaleRuleVO; +import org.apache.shenyu.admin.service.ScaleRuleService; +import org.apache.shenyu.common.utils.ListUtil; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import java.util.List; +import java.util.stream.Collectors; + +/** + * Implementation of the ScaleRuleService. + */ +@Service +public class ScaleRuleServiceImpl implements ScaleRuleService { + + private final ScaleRuleMapper scaleRuleMapper; + + public ScaleRuleServiceImpl(final ScaleRuleMapper scaleRuleMapper) { + this.scaleRuleMapper = scaleRuleMapper; + } + + + /** + * selectAll. + * + * @return java.util.List + */ + @Override + public List selectAll() { + return ListUtil.map(scaleRuleMapper.selectAll(), ScaleRuleVO::buildScaleRuleVO); + } + + /** + * find page of scale rule by query. + * + * @param scaleRuleQuery {@linkplain ScaleRuleQuery} + * @return {@linkplain CommonPager} + */ + @Override + @Pageable + public CommonPager listByPage(final ScaleRuleQuery scaleRuleQuery) { + return PageResultUtils.result(scaleRuleQuery.getPageParameter(), () -> scaleRuleMapper.selectByQuery(scaleRuleQuery) + .stream() + .map(ScaleRuleVO::buildScaleRuleVO) + .collect(Collectors.toList())); + } + + /** + * find scale rule by id. + * + * @param id primary key + * @return {@linkplain ScaleRuleVO} + */ + @Override + public ScaleRuleVO findById(final String id) { + return ScaleRuleVO.buildScaleRuleVO(scaleRuleMapper.selectByPrimaryKey(id)); + } + + /** + * create or update rule info. + * + * @param scaleRuleDTO {@linkplain ScaleRuleDTO} + * @return rows + */ + @Override + @Transactional(rollbackFor = Exception.class) + public int createOrUpdate(final ScaleRuleDTO scaleRuleDTO) { + return ScaleRuleService.super.createOrUpdate(scaleRuleDTO); + } + + /** + * create or update rule. + * + * @param scaleRuleDTO {@linkplain ScaleRuleDTO} + * @return rows int + */ + @Override + public int create(final ScaleRuleDTO scaleRuleDTO) { + final ScaleRuleDO scaleRuleDO = ScaleRuleDO.buildScaleRuleDO(scaleRuleDTO); + return scaleRuleMapper.insertSelective(scaleRuleDO); + } + + /** + * create or update rule. + * + * @param scaleRuleDTO {@linkplain ScaleRuleDTO} + * @return rows int + */ + @Override + public int update(final ScaleRuleDTO scaleRuleDTO) { + final ScaleRuleDO after = ScaleRuleDO.buildScaleRuleDO(scaleRuleDTO); + return scaleRuleMapper.updateByPrimaryKey(after); + } + + /** + * delete rules. + * + * @param ids primary key + * @return rows int + */ + @Override + public int delete(final List ids) { + return scaleRuleMapper.delete(ids); + } +} diff --git a/shenyu-admin/src/main/resources/mappers/scale-history-sqlmap.xml b/shenyu-admin/src/main/resources/mappers/scale-history-sqlmap.xml new file mode 100644 index 000000000000..88f3b30a266e --- /dev/null +++ b/shenyu-admin/src/main/resources/mappers/scale-history-sqlmap.xml @@ -0,0 +1,161 @@ + + + + + + + + + + + + + + + + + + id, config_id, num, `action`, date_created, date_updated + + + msg + + + + + delete from scale_history + where id = #{id,jdbcType=VARCHAR} + + + + SELECT LAST_INSERT_ID() + + insert into scale_history (config_id, num, `action`, + date_created, date_updated, msg + ) + values (#{configId,jdbcType=INTEGER}, #{num,jdbcType=INTEGER}, #{action,jdbcType=INTEGER}, + #{dateCreated,jdbcType=TIMESTAMP}, #{dateUpdated,jdbcType=TIMESTAMP}, #{msg,jdbcType=LONGVARCHAR} + ) + + + + SELECT LAST_INSERT_ID() + + insert into scale_history + + + config_id, + + + num, + + + `action`, + + + date_created, + + + date_updated, + + + msg, + + + + + #{configId,jdbcType=INTEGER}, + + + #{num,jdbcType=INTEGER}, + + + #{action,jdbcType=INTEGER}, + + + #{dateCreated,jdbcType=TIMESTAMP}, + + + #{dateUpdated,jdbcType=TIMESTAMP}, + + + #{msg,jdbcType=LONGVARCHAR}, + + + + + update scale_history + + + config_id = #{configId,jdbcType=INTEGER}, + + + num = #{num,jdbcType=INTEGER}, + + + `action` = #{action,jdbcType=INTEGER}, + + + date_created = #{dateCreated,jdbcType=TIMESTAMP}, + + + date_updated = #{dateUpdated,jdbcType=TIMESTAMP}, + + + msg = #{msg,jdbcType=LONGVARCHAR}, + + + where id = #{id,jdbcType=VARCHAR} + + + update scale_history + set config_id = #{configId,jdbcType=INTEGER}, + num = #{num,jdbcType=INTEGER}, + `action` = #{action,jdbcType=INTEGER}, + date_created = #{dateCreated,jdbcType=TIMESTAMP}, + date_updated = #{dateUpdated,jdbcType=TIMESTAMP}, + msg = #{msg,jdbcType=LONGVARCHAR} + where id = #{id,jdbcType=VARCHAR} + + + update scale_history + set config_id = #{configId,jdbcType=INTEGER}, + num = #{num,jdbcType=INTEGER}, + `action` = #{action,jdbcType=INTEGER}, + date_created = #{dateCreated,jdbcType=TIMESTAMP}, + date_updated = #{dateUpdated,jdbcType=TIMESTAMP} + where id = #{id,jdbcType=VARCHAR} + + + \ No newline at end of file diff --git a/shenyu-admin/src/main/resources/mappers/scale-policy-sqlmap.xml b/shenyu-admin/src/main/resources/mappers/scale-policy-sqlmap.xml new file mode 100644 index 000000000000..6ef188059ce9 --- /dev/null +++ b/shenyu-admin/src/main/resources/mappers/scale-policy-sqlmap.xml @@ -0,0 +1,152 @@ + + + + + + + + + + + + + + + + + id, sort, `status`, num, begin_time, end_time, date_created, date_updated + + + + + delete from scale_policy + where id = #{id,jdbcType=VARCHAR} + + + insert into scale_policy (id, sort, `status`, num, + begin_time, end_time, date_created, + date_updated) + values (#{id,jdbcType=VARCHAR}, #{sort,jdbcType=INTEGER}, #{status,jdbcType=INTEGER}, #{num,jdbcType=INTEGER}, + #{beginTime,jdbcType=TIMESTAMP}, #{endTime,jdbcType=TIMESTAMP}, #{dateCreated,jdbcType=TIMESTAMP}, + #{dateUpdated,jdbcType=TIMESTAMP}) + + + insert into scale_policy + + id, + + sort, + + + `status`, + + + num, + + + begin_time, + + + end_time, + + + date_created, + + + date_updated, + + + + #{id, jdbcType=VARCHAR}, + + #{sort,jdbcType=INTEGER}, + + + #{status,jdbcType=INTEGER}, + + + #{num,jdbcType=INTEGER}, + + + #{beginTime,jdbcType=TIMESTAMP}, + + + #{endTime,jdbcType=TIMESTAMP}, + + + #{dateCreated,jdbcType=TIMESTAMP}, + + + #{dateUpdated,jdbcType=TIMESTAMP}, + + + + + update scale_policy + + + sort = #{sort,jdbcType=INTEGER}, + + + `status` = #{status,jdbcType=INTEGER}, + + + num = #{num,jdbcType=INTEGER}, + + + begin_time = #{beginTime,jdbcType=TIMESTAMP}, + + + end_time = #{endTime,jdbcType=TIMESTAMP}, + + + date_created = #{dateCreated,jdbcType=TIMESTAMP}, + + + date_updated = #{dateUpdated,jdbcType=TIMESTAMP}, + + + where id = #{id,jdbcType=VARCHAR} + + + update scale_policy + set sort = #{sort,jdbcType=INTEGER}, + `status` = #{status,jdbcType=INTEGER}, + num = #{num,jdbcType=INTEGER}, + begin_time = #{beginTime,jdbcType=TIMESTAMP}, + end_time = #{endTime,jdbcType=TIMESTAMP}, + date_created = #{dateCreated,jdbcType=TIMESTAMP}, + date_updated = #{dateUpdated,jdbcType=TIMESTAMP} + where id = #{id,jdbcType=VARCHAR} + + + \ No newline at end of file diff --git a/shenyu-admin/src/main/resources/mappers/scale-rule-sqlmap.xml b/shenyu-admin/src/main/resources/mappers/scale-rule-sqlmap.xml new file mode 100644 index 000000000000..9937a5b85f9c --- /dev/null +++ b/shenyu-admin/src/main/resources/mappers/scale-rule-sqlmap.xml @@ -0,0 +1,217 @@ + + + + + + + + + + + + + + + + + + + + + + + + + and ${criterion.condition} + + + and ${criterion.condition} #{criterion.value} + + + and ${criterion.condition} #{criterion.value} and #{criterion.secondValue} + + + and ${criterion.condition} + + #{listItem} + + + + + + + + + + + id, metric_name, `type`, sort, `status`, minimum, maximum, date_created, date_updated + + + + + delete from scale_rule + where id = #{id,jdbcType=VARCHAR} + + + insert into scale_rule (id, metric_name, `type`, sort, + `status`, minimum, maximum, + date_created, date_updated) + values (#{id,jdbcType=VARCHAR}, #{metricName,jdbcType=VARCHAR}, #{type,jdbcType=INTEGER}, #{sort,jdbcType=INTEGER}, + #{status,jdbcType=INTEGER}, #{minimum,jdbcType=VARCHAR}, #{maximum,jdbcType=VARCHAR}, + #{dateCreated,jdbcType=TIMESTAMP}, #{dateUpdated,jdbcType=TIMESTAMP}) + + + insert into scale_rule + + id, + + metric_name, + + + `type`, + + + sort, + + + `status`, + + + minimum, + + + maximum, + + + date_created, + + + date_updated, + + + + #{id, jdbcType=VARCHAR}, + + #{metricName,jdbcType=VARCHAR}, + + + #{type,jdbcType=INTEGER}, + + + #{sort,jdbcType=INTEGER}, + + + #{status,jdbcType=INTEGER}, + + + #{minimum,jdbcType=VARCHAR}, + + + #{maximum,jdbcType=VARCHAR}, + + + #{dateCreated,jdbcType=TIMESTAMP}, + + + #{dateUpdated,jdbcType=TIMESTAMP}, + + + + + + update scale_rule + + + metric_name = #{metricName,jdbcType=VARCHAR}, + + + `type` = #{type,jdbcType=INTEGER}, + + + sort = #{sort,jdbcType=INTEGER}, + + + `status` = #{status,jdbcType=INTEGER}, + + + minimum = #{minimum,jdbcType=VARCHAR}, + + + maximum = #{maximum,jdbcType=VARCHAR}, + + + date_created = #{dateCreated,jdbcType=TIMESTAMP}, + + + date_updated = #{dateUpdated,jdbcType=TIMESTAMP}, + + + where id = #{id,jdbcType=VARCHAR} + + + update scale_rule + set metric_name = #{metricName,jdbcType=VARCHAR}, + `type` = #{type,jdbcType=INTEGER}, + sort = #{sort,jdbcType=INTEGER}, + `status` = #{status,jdbcType=INTEGER}, + minimum = #{minimum,jdbcType=VARCHAR}, + maximum = #{maximum,jdbcType=VARCHAR}, + date_created = #{dateCreated,jdbcType=TIMESTAMP}, + date_updated = #{dateUpdated,jdbcType=TIMESTAMP} + where id = #{id,jdbcType=VARCHAR} + + + + + DELETE FROM scale_rule + WHERE id IN + + #{id, jdbcType=VARCHAR} + + + \ No newline at end of file diff --git a/shenyu-admin/src/main/resources/sql-script/h2/schema.sql b/shenyu-admin/src/main/resources/sql-script/h2/schema.sql index 0803c80123fc..268ac35235ce 100755 --- a/shenyu-admin/src/main/resources/sql-script/h2/schema.sql +++ b/shenyu-admin/src/main/resources/sql-script/h2/schema.sql @@ -1342,8 +1342,55 @@ INSERT IGNORE INTO `permission` (`id`, `object_id`, `resource_id`, `date_created INSERT IGNORE INTO `permission` (`id`, `object_id`, `resource_id`, `date_created`, `date_updated`) VALUES ('1792779493541343266', '1346358560427216896', '1792749362445840485', '2024-06-25 20:00:00.000', '2024-06-25 20:00:00.000'); INSERT IGNORE INTO `permission` (`id`, `object_id`, `resource_id`, `date_created`, `date_updated`) VALUES ('1792779493541343267', '1346358560427216896', '1792749362445840486', '2024-06-25 20:00:00.000', '2024-06-25 20:00:00.000'); + +CREATE TABLE IF NOT EXISTS `scale_policy` +( + `id` varchar(128) NOT NULL COMMENT 'primary key id', + `sort` int NOT NULL COMMENT 'sort', + `status` int NOT NULL COMMENT 'status 1:enable 0:disable', + `num` int COMMENT 'number of bootstrap', + `begin_time` datetime COMMENT 'begin time', + `end_time` datetime COMMENT 'end time', + `date_created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP(3) COMMENT 'create time', + `date_updated` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP(3) ON UPDATE CURRENT_TIMESTAMP(3) COMMENT 'update time', + PRIMARY KEY (`id`) +); + +INSERT IGNORE INTO `scale_policy` (`id`, `sort`, `status`, `num`, `begin_time`, `end_time`, `date_created`, `date_updated`) VALUES ('1', 1, 0, 10, NULL, NULL, '2024-07-31 20:00:00.000', '2024-07-31 20:00:00.000'); +INSERT IGNORE INTO `scale_policy` (`id`, `sort`, `status`, `num`, `begin_time`, `end_time`, `date_created`, `date_updated`) VALUES ('2', 2, 0, 10, '2024-07-31 20:00:00.000', '2024-08-01 20:00:00.000', '2024-07-31 20:00:00.000', '2024-07-31 20:00:00.000'); +INSERT IGNORE INTO `scale_policy` (`id`, `sort`, `status`, `num`, `begin_time`, `end_time`, `date_created`, `date_updated`) VALUES ('3', 3, 0, NULL, NULL, NULL, '2024-07-31 20:00:00.000', '2024-07-31 20:00:00.000'); + +CREATE TABLE IF NOT EXISTS `scale_rule` +( + `id` varchar(128) NOT NULL COMMENT 'primary key id', + `metric_name` varchar(128) NOT NULL COMMENT 'metric name', + `type` int NOT NULL COMMENT 'type 0:shenyu 1:k8s 2:others', + `sort` int NOT NULL COMMENT 'sort', + `status` int NOT NULL COMMENT 'status 1:enable 0:disable', + `minimum` varchar(128) COMMENT 'minimum of metric', + `maximum` varchar(128) COMMENT 'maximum of metric', + `date_created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP(3) COMMENT 'create time', + `date_updated` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP(3) ON UPDATE CURRENT_TIMESTAMP(3) COMMENT 'update time', + PRIMARY KEY (`id`) +); + +CREATE TABLE IF NOT EXISTS `scale_history` +( + `id` varchar(128) NOT NULL COMMENT 'primary key id', + `config_id` int NOT NULL COMMENT '0:manual 1:period 2:dynamic', + `num` int NOT NULL COMMENT 'number of bootstrap', + `action` int NOT NULL COMMENT 'status 1:enable 0:disable', + `msg` text COMMENT 'message', + `date_created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP(3) COMMENT 'create time', + `date_updated` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP(3) ON UPDATE CURRENT_TIMESTAMP(3) COMMENT 'update time', + PRIMARY KEY (`id`) +); + + +ALTER TABLE `selector` ADD COLUMN `namespace_id` varchar(50) NULL COMMENT 'namespaceId' AFTER `match_restful`; + ALTER TABLE `selector` ADD COLUMN `namespace_id` varchar(50) NULL COMMENT 'namespaceId' AFTER `match_restful`; ALTER TABLE `rule` ADD COLUMN `namespace_id` varchar(50) NULL COMMENT 'namespaceId' AFTER `match_restful`; -ALTER TABLE `meta_data` ADD COLUMN `namespace_id` varchar(50) NULL COMMENT 'namespaceId' ; \ No newline at end of file +ALTER TABLE `meta_data` ADD COLUMN `namespace_id` varchar(50) NULL COMMENT 'namespaceId' ; diff --git a/shenyu-admin/src/test/java/org/apache/shenyu/admin/mapper/ScalePolicyMapperTest.java b/shenyu-admin/src/test/java/org/apache/shenyu/admin/mapper/ScalePolicyMapperTest.java new file mode 100644 index 000000000000..c30a60430381 --- /dev/null +++ b/shenyu-admin/src/test/java/org/apache/shenyu/admin/mapper/ScalePolicyMapperTest.java @@ -0,0 +1,127 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.shenyu.admin.mapper; + +import jakarta.annotation.Resource; +import org.apache.shenyu.admin.AbstractSpringIntegrationTest; +import org.apache.shenyu.admin.model.entity.ScalePolicyDO; +import org.apache.shenyu.common.utils.UUIDUtils; +import org.junit.jupiter.api.Test; + +import java.util.Date; +import java.sql.Timestamp; +import java.time.LocalDateTime; +import java.time.ZoneId; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.equalTo; +import static org.junit.jupiter.api.Assertions.assertEquals; + +/** + * Test cases for ScalePolicyMapper. + */ +public final class ScalePolicyMapperTest extends AbstractSpringIntegrationTest { + + @Resource + private ScalePolicyMapper scalePolicyMapper; + + @Test + void deleteByPrimaryKey() { + ScalePolicyDO scalePolicyDO = buildScalePolicyDO(); + int insert = scalePolicyMapper.insertSelective(scalePolicyDO); + assertThat(insert, equalTo(1)); + + int delete = scalePolicyMapper.deleteByPrimaryKey(scalePolicyDO.getId()); + assertThat(delete, equalTo(1)); + + ScalePolicyDO result = scalePolicyMapper.selectByPrimaryKey(scalePolicyDO.getId()); + assertThat(result, equalTo(null)); + } + + @Test + void insert() { + ScalePolicyDO scalePolicyDO = buildScalePolicyDO(); + int insert = scalePolicyMapper.insert(scalePolicyDO); + assertThat(insert, equalTo(1)); + } + + @Test + void insertSelective() { + ScalePolicyDO scalePolicyDO = buildScalePolicyDO(); + int insert = scalePolicyMapper.insertSelective(scalePolicyDO); + assertThat(insert, equalTo(1)); + } + + @Test + void selectByPrimaryKey() { + ScalePolicyDO resultDO = scalePolicyMapper.selectByPrimaryKey("1"); + // assertNotNull(resultDO); + assertEquals("1", resultDO.getId()); + assertEquals(1, resultDO.getSort()); + assertEquals(0, resultDO.getStatus()); + assertEquals(10, resultDO.getNum()); + } + + @Test + void updateByPrimaryKeySelective() { + ScalePolicyDO scalePolicyDO = buildScalePolicyDO(); + int insert = scalePolicyMapper.insert(scalePolicyDO); + assertThat(insert, equalTo(1)); + + scalePolicyDO.setNum(14); + Date beginTime = scalePolicyDO.getBeginTime(); + scalePolicyDO.setBeginTime(null); + int update = scalePolicyMapper.updateByPrimaryKeySelective(scalePolicyDO); + assertThat(update, equalTo(1)); + ScalePolicyDO result = scalePolicyMapper.selectByPrimaryKey(scalePolicyDO.getId()); + scalePolicyDO.setBeginTime(beginTime); + assertThat(result, equalTo(scalePolicyDO)); + } + + @Test + void updateByPrimaryKey() { + ScalePolicyDO scalePolicyDO = buildScalePolicyDO(); + int insert = scalePolicyMapper.insert(scalePolicyDO); + assertThat(insert, equalTo(1)); + + scalePolicyDO.setNum(16); + int update = scalePolicyMapper.updateByPrimaryKey(scalePolicyDO); + assertThat(update, equalTo(1)); + ScalePolicyDO result = scalePolicyMapper.selectByPrimaryKey(scalePolicyDO.getId()); + assertThat(result, equalTo(scalePolicyDO)); + } + + private ScalePolicyDO buildScalePolicyDO() { + Timestamp now = new Timestamp(System.currentTimeMillis()); + String id = UUIDUtils.getInstance().generateShortUuid(); + LocalDateTime begin = LocalDateTime.of(2024, 7, 31, 20, 0, 0, 0); + LocalDateTime end = LocalDateTime.of(2024, 8, 11, 20, 0, 0, 0); + Date date1 = Date.from(begin.atZone(ZoneId.systemDefault()).toInstant()); + Date date2 = Date.from(end.atZone(ZoneId.systemDefault()).toInstant()); + return ScalePolicyDO.builder() + .id(id) + .sort(1) + .status(0) + .num(10) + .beginTime(date1) + .endTime(date2) + .dateCreated(now) + .dateUpdated(now) + .build(); + } +} diff --git a/shenyu-common/src/main/java/org/apache/shenyu/common/utils/DateUtils.java b/shenyu-common/src/main/java/org/apache/shenyu/common/utils/DateUtils.java index c6eae614c55e..35d8dfa23fcd 100644 --- a/shenyu-common/src/main/java/org/apache/shenyu/common/utils/DateUtils.java +++ b/shenyu-common/src/main/java/org/apache/shenyu/common/utils/DateUtils.java @@ -17,6 +17,8 @@ package org.apache.shenyu.common.utils; +import org.apache.commons.lang3.StringUtils; + import java.time.LocalDateTime; import java.time.OffsetDateTime; import java.time.ZoneOffset; @@ -125,4 +127,15 @@ public static String localDateTimeToString(final LocalDateTime localDateTime, fi DateTimeFormatter formatter = DateTimeFormatter.ofPattern(pattern); return localDateTime.format(formatter); } + + /** + * isValidDate. + * + * @param dateStr dateStr + * @return boolean + */ + public static boolean isValidDate(final String dateStr) { + return StringUtils.isNotBlank(dateStr); + } + }