You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shenyu.apache.org by "Terminator111 (via GitHub)" <gi...@apache.org> on 2024/08/01 11:06:41 UTC
[PR] [type:feat]Add dynamically scale admin module sql and mapper [shenyu]
Terminator111 opened a new pull request, #5602:
URL: https://github.com/apache/shenyu/pull/5602
Make sure that:
- [x] You have read the [contribution guidelines](https://shenyu.apache.org/community/contributor-guide).
- [x] You submit test cases (unit or integration tests) that back your changes.
- [x] Your local test passed `./mvnw clean install -Dmaven.javadoc.skip=true`.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@shenyu.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [type:feat]Add dynamically scale admin module [shenyu]
Posted by "moremind (via GitHub)" <gi...@apache.org>.
moremind commented on PR #5602:
URL: https://github.com/apache/shenyu/pull/5602#issuecomment-2263236346
not delete icon
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@shenyu.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [type:feat]Add dynamically scale admin module [shenyu]
Posted by "misaya295 (via GitHub)" <gi...@apache.org>.
misaya295 commented on code in PR #5602:
URL: https://github.com/apache/shenyu/pull/5602#discussion_r1754928333
##########
db/init/mysql/schema.sql:
##########
@@ -2371,8 +2371,61 @@ 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`.`selector` ADD COLUMN `namespace_id` varchar(50) NULL COMMENT 'namespaceId' AFTER `match_restful`;
Review Comment:
Duplicate sql
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@shenyu.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [type:feat]Add dynamically scale admin module [shenyu]
Posted by "Terminator111 (via GitHub)" <gi...@apache.org>.
Terminator111 commented on code in PR #5602:
URL: https://github.com/apache/shenyu/pull/5602#discussion_r1743948373
##########
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(item.getBeginTime())
Review Comment:
when use manual strategy or dynamic strategy, there is not need to fill it.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@shenyu.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [type:feat]Add dynamically scale admin module [shenyu]
Posted by "misaya295 (via GitHub)" <gi...@apache.org>.
misaya295 commented on code in PR #5602:
URL: https://github.com/apache/shenyu/pull/5602#discussion_r1743908828
##########
shenyu-admin/src/main/java/org/apache/shenyu/admin/model/dto/ScalePolicyDTO.java:
##########
@@ -0,0 +1,323 @@
+/*
+ * 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.util.Objects;
+
+/**
+ * this is 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 String beginTime;
Review Comment:
use localdatetime
##########
shenyu-admin/src/main/java/org/apache/shenyu/admin/model/dto/ScalePolicyDTO.java:
##########
@@ -0,0 +1,323 @@
+/*
+ * 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.util.Objects;
+
+/**
+ * this is 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 String beginTime;
+
+ /**
+ * end time.
+ */
+ private String endTime;
Review Comment:
use localdatetime
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@shenyu.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [type:feat]Add dynamically scale admin module [shenyu]
Posted by "misaya295 (via GitHub)" <gi...@apache.org>.
misaya295 commented on PR #5602:
URL: https://github.com/apache/shenyu/pull/5602#issuecomment-2335107614
@Terminator111 check ci pls
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@shenyu.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [type:feat]Add dynamically scale admin module [shenyu]
Posted by "Terminator111 (via GitHub)" <gi...@apache.org>.
Terminator111 commented on PR #5602:
URL: https://github.com/apache/shenyu/pull/5602#issuecomment-2329305470
> you should add sql in upgrade script, for example, 2.6.1-2.7.0-mysql.sql, 2.6.1-2.7.0-pg.sql, and so on...
done.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@shenyu.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [type:feat]Add dynamically scale admin module [shenyu]
Posted by "moremind (via GitHub)" <gi...@apache.org>.
moremind commented on PR #5602:
URL: https://github.com/apache/shenyu/pull/5602#issuecomment-2329149700
you should add sql in upgrade script, for example, 2.6.1-2.7.0-mysql.sql, 2.6.1-2.7.0-pg.sql, and so on...
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@shenyu.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [type:feat]Add dynamically scale admin module [shenyu]
Posted by "moremind (via GitHub)" <gi...@apache.org>.
moremind commented on code in PR #5602:
URL: https://github.com/apache/shenyu/pull/5602#discussion_r1743870770
##########
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(item.getBeginTime())
Review Comment:
Why is the begintime null?
##########
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("")
Review Comment:
remove `("")`, just `@PutMapping`
##########
shenyu-admin/src/main/java/org/apache/shenyu/admin/model/dto/ScalePolicyDTO.java:
##########
@@ -0,0 +1,323 @@
+/*
+ * 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.util.Objects;
+
+/**
+ * this is 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 String beginTime;
+
+ /**
+ * end time.
+ */
+ private String endTime;
+
+ public ScalePolicyDTO() {
+ }
+
+ public ScalePolicyDTO(final String id,
+ @NotNull final Integer sort,
Review Comment:
remove `@Notnull`
##########
shenyu-common/src/main/java/org/apache/shenyu/common/utils/DateUtils.java:
##########
@@ -125,4 +125,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 dateStr != null && !dateStr.trim().isEmpty();
Review Comment:
use StringUtils.isNotBlank
##########
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<ScaleRuleVO> 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("")
Review Comment:
remove `("")`
##########
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
Review Comment:
same question
##########
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("")
Review Comment:
remove `("")`
##########
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<ScaleRuleVO> 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("")
Review Comment:
remove `("")`
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@shenyu.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [type:feat]Add dynamically scale admin module [shenyu]
Posted by "misaya295 (via GitHub)" <gi...@apache.org>.
misaya295 commented on code in PR #5602:
URL: https://github.com/apache/shenyu/pull/5602#discussion_r1700108227
##########
.idea/vcs.xml:
##########
Review Comment:
The .idea file does not need to be submitted
##########
shenyu-admin/src/test/java/org/apache/shenyu/admin/mapper/ScaleRuleMapperTest.java:
##########
@@ -0,0 +1,24 @@
+/*
+ * 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.shenyu.admin.AbstractSpringIntegrationTest;
+
+public final class ScaleRuleMapperTest extends AbstractSpringIntegrationTest {
Review Comment:
Empty tests may not be submitted
##########
.idea/icon.svg:
##########
Review Comment:
The .idea file does not need to be submitted
##########
shenyu-admin/src/main/java/org/apache/shenyu/admin/model/entity/ScalePolicyDO.java:
##########
@@ -0,0 +1,347 @@
+/*
+ * 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;
+
+/**
+ * Table: scale_policy
+ */
+public final class ScalePolicyDO extends BaseDO{
Review Comment:
{ one space after, please check the code style
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@shenyu.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [type:feat]Add dynamically scale admin module [shenyu]
Posted by "Terminator111 (via GitHub)" <gi...@apache.org>.
Terminator111 commented on PR #5602:
URL: https://github.com/apache/shenyu/pull/5602#issuecomment-2290586629
> not delete icon
done.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@shenyu.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [type:feat]Add dynamically scale admin module [shenyu]
Posted by "misaya295 (via GitHub)" <gi...@apache.org>.
misaya295 commented on code in PR #5602:
URL: https://github.com/apache/shenyu/pull/5602#discussion_r1720774454
##########
shenyu-admin/src/test/java/org/apache/shenyu/admin/mapper/ScalePolicyMapperTest.java:
##########
@@ -0,0 +1,64 @@
+/*
+ * 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.junit.jupiter.api.Test;
+
+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() {
Review Comment:
Please complete the unit test
##########
shenyu-admin/src/test/java/org/apache/shenyu/admin/mapper/ScalePolicyMapperTest.java:
##########
@@ -0,0 +1,64 @@
+/*
+ * 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.junit.jupiter.api.Test;
+
+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() {
+ }
+
+ @Test
+ void insert() {
+ }
+
+ @Test
+ void insertSelective() {
+ }
+
+ @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() {
+ }
Review Comment:
same question
##########
shenyu-admin/src/test/java/org/apache/shenyu/admin/mapper/ScalePolicyMapperTest.java:
##########
@@ -0,0 +1,64 @@
+/*
+ * 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.junit.jupiter.api.Test;
+
+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() {
+ }
+
+ @Test
+ void insert() {
+ }
+
+ @Test
+ void insertSelective() {
+ }
+
+ @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() {
+ }
+
+ @Test
+ void updateByPrimaryKey() {
+ }
Review Comment:
same question
##########
shenyu-admin/src/test/java/org/apache/shenyu/admin/mapper/ScalePolicyMapperTest.java:
##########
@@ -0,0 +1,64 @@
+/*
+ * 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.junit.jupiter.api.Test;
+
+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() {
+ }
+
+ @Test
+ void insert() {
+ }
+
+ @Test
+ void insertSelective() {
+ }
Review Comment:
same question
##########
shenyu-admin/pom.xml:
##########
@@ -352,6 +352,12 @@
<artifactId>shenyu-admin-listener-zookeeper</artifactId>
<version>${project.version}</version>
</dependency>
+ <dependency>
+ <groupId>joda-time</groupId>
+ <artifactId>joda-time</artifactId>
Review Comment:
remove useless dependencies
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@shenyu.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [type:feat]Add dynamically scale admin module [shenyu]
Posted by "moremind (via GitHub)" <gi...@apache.org>.
moremind commented on code in PR #5602:
URL: https://github.com/apache/shenyu/pull/5602#discussion_r1720784481
##########
shenyu-admin/src/main/java/org/apache/shenyu/admin/controller/ScalePolicyController.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.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 id primary key
+ * @param scalePolicyDTO scale policy info
+ * @return ShenyuAdminResult
+ */
+ @PutMapping("/{id}")
+ public ShenyuAdminResult updateScalePolicy(@PathVariable("id") @Valid
+ @Existed(provider = ScalePolicyMapper.class,
Review Comment:
`@valid` should put on another line
##########
shenyu-admin/src/main/java/org/apache/shenyu/admin/controller/ScalePolicyController.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.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 id primary key
+ * @param scalePolicyDTO scale policy info
+ * @return ShenyuAdminResult
+ */
+ @PutMapping("/{id}")
+ public ShenyuAdminResult updateScalePolicy(@PathVariable("id") @Valid
+ @Existed(provider = ScalePolicyMapper.class,
+ message = "scale policy is not existed") final String id,
+ @Valid @RequestBody final ScalePolicyDTO scalePolicyDTO) {
+ scalePolicyDTO.setId(id);
Review Comment:
the id should in scalePolicyDTO
##########
shenyu-admin/src/main/java/org/apache/shenyu/admin/controller/ScalePolicyController.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.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 id primary key
+ * @param scalePolicyDTO scale policy info
+ * @return ShenyuAdminResult
+ */
+ @PutMapping("/{id}")
+ public ShenyuAdminResult updateScalePolicy(@PathVariable("id") @Valid
+ @Existed(provider = ScalePolicyMapper.class,
+ message = "scale policy is not existed") final String id,
+ @Valid @RequestBody final ScalePolicyDTO scalePolicyDTO) {
+ scalePolicyDTO.setId(id);
Review Comment:
you can check in pathvaraiable and body
##########
shenyu-admin/src/main/java/org/apache/shenyu/admin/model/dto/ScalePolicyDTO.java:
##########
@@ -0,0 +1,323 @@
+/*
+ * 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.util.Objects;
+
+/**
+ * this is 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 String beginTime;
+
+ /**
+ * end time.
+ */
+ private String endTime;
+
+ public ScalePolicyDTO() {
+ }
+
+ public ScalePolicyDTO(final String id,
+ @NotNull final Integer sort,
+ @NotNull final Integer status,
+ final Integer num,
+ final String beginTime,
+ final String 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 @Existed(provider = ScalePolicyMapper.class, nullOfIgnore = true, message = "scale policy is not existed") String getId() {
+ return id;
+ }
+
+ /**
+ * Sets the id.
+ *
+ * @param id id
+ */
+ public void setId(@Existed(provider = ScalePolicyMapper.class, nullOfIgnore = true, message = "scale policy is not existed") final String id) {
+ this.id = id;
+ }
+
+ /**
+ * Gets the value of sort.
+ *
+ * @return the value of sort
+ */
+ public @NotNull Integer getSort() {
+ return sort;
+ }
+
+ /**
+ * Sets the sort.
+ *
+ * @param sort sort
+ */
+ public void setSort(@NotNull final Integer sort) {
+ this.sort = sort;
+ }
+
+ /**
+ * Gets the value of status.
+ *
+ * @return the value of status
+ */
+ public @NotNull Integer getStatus() {
+ return status;
+ }
+
+ /**
+ * Sets the status.
+ *
+ * @param status status
+ */
+ public void setStatus(@NotNull 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;
+ }
+
+ /**
+ * 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 @Existed(provider = ScalePolicyMapper.class, nullOfIgnore = true, message = "scale policy is not existed") String id;
Review Comment:
`
@Existed(provider = ScalePolicyMapper.class, nullOfIgnore = true, message = "scale policy is not existed")
private String id;
`
##########
shenyu-admin/src/main/java/org/apache/shenyu/admin/controller/ScaleRlueController.java:
##########
@@ -0,0 +1,138 @@
+/*
+ * 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<ScaleRuleVO> 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
Review Comment:
`@valid` same question
##########
shenyu-admin/src/main/java/org/apache/shenyu/admin/model/dto/ScalePolicyDTO.java:
##########
@@ -0,0 +1,323 @@
+/*
+ * 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.util.Objects;
+
+/**
+ * this is 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 String beginTime;
+
+ /**
+ * end time.
+ */
+ private String endTime;
+
+ public ScalePolicyDTO() {
+ }
+
+ public ScalePolicyDTO(final String id,
+ @NotNull final Integer sort,
+ @NotNull final Integer status,
+ final Integer num,
+ final String beginTime,
+ final String 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 @Existed(provider = ScalePolicyMapper.class, nullOfIgnore = true, message = "scale policy is not existed") String getId() {
+ return id;
+ }
+
+ /**
+ * Sets the id.
+ *
+ * @param id id
+ */
+ public void setId(@Existed(provider = ScalePolicyMapper.class, nullOfIgnore = true, message = "scale policy is not existed") final String id) {
+ this.id = id;
+ }
+
+ /**
+ * Gets the value of sort.
+ *
+ * @return the value of sort
+ */
+ public @NotNull Integer getSort() {
+ return sort;
+ }
+
+ /**
+ * Sets the sort.
+ *
+ * @param sort sort
+ */
+ public void setSort(@NotNull final Integer sort) {
+ this.sort = sort;
+ }
+
+ /**
+ * Gets the value of status.
+ *
+ * @return the value of status
+ */
+ public @NotNull Integer getStatus() {
+ return status;
+ }
+
+ /**
+ * Sets the status.
+ *
+ * @param status status
+ */
+ public void setStatus(@NotNull 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;
+ }
+
+ /**
+ * 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 @Existed(provider = ScalePolicyMapper.class, nullOfIgnore = true, message = "scale policy is not existed") String id;
Review Comment:
the annotation location is ugly
##########
shenyu-admin/src/main/java/org/apache/shenyu/admin/controller/ScaleRlueController.java:
##########
@@ -0,0 +1,138 @@
+/*
+ * 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<ScaleRuleVO> 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 id id
+ * @param scaleRuleDTO scaleRuleDTO
+ * @return ShenyuAdminResult
+ */
+ @PutMapping("/{id}")
+ public ShenyuAdminResult updateRule(@PathVariable("id") @Valid
+ @Existed(provider = ScaleRuleMapper.class,
+ message = "scale rule is not existed") final String id,
+ @Valid @RequestBody final ScaleRuleDTO scaleRuleDTO) {
+ scaleRuleDTO.setId(id);
Review Comment:
same question
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@shenyu.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org