From e186064d4b3369c8e2eb151257559692d64cd7eb Mon Sep 17 00:00:00 2001 From: baymax55 <35788491+baymax55@users.noreply.github.com> Date: Sun, 9 Oct 2022 10:11:09 +0800 Subject: [PATCH 1/7] Add note for Authentication (#774) --- hippo4j-server/conf/application.properties | 3 +++ hippo4j-server/src/main/resources/application.properties | 2 ++ 2 files changed, 5 insertions(+) diff --git a/hippo4j-server/conf/application.properties b/hippo4j-server/conf/application.properties index b8779e7c..602cd38d 100644 --- a/hippo4j-server/conf/application.properties +++ b/hippo4j-server/conf/application.properties @@ -20,6 +20,9 @@ tenant=hippo4j hippo4j.core.clean-history-data-period=30 hippo4j.core.clean-history-data-enable=true +### Whether to enable authentication. +hippo4j.core.auth.enabled=false + ### Use netty to report thread pool monitoring data. The default is http. # hippo4j.core.monitor.report-type=netty diff --git a/hippo4j-server/src/main/resources/application.properties b/hippo4j-server/src/main/resources/application.properties index eef0f110..865f88f3 100644 --- a/hippo4j-server/src/main/resources/application.properties +++ b/hippo4j-server/src/main/resources/application.properties @@ -20,6 +20,8 @@ tenant=hippo4j ### Regularly clean up the historical running data of thread pool. unit: minute. hippo4j.core.clean-history-data-period=30 hippo4j.core.clean-history-data-enable=true + +### Whether to enable authentication. hippo4j.core.auth.enabled=false ### Initialize the database dialect class. From fbfdecaef1df5a4b9c0bca6fac497ffc1d5a6cc7 Mon Sep 17 00:00:00 2001 From: pirme Date: Sun, 9 Oct 2022 10:11:25 +0800 Subject: [PATCH 2/7] Update the list of contributors --- README.md | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index e1f77bd2..9ba87985 100644 --- a/README.md +++ b/README.md @@ -171,6 +171,13 @@ Hippo-4J 通过对 JDK 线程池增强,以及扩展三方框架底层线程池 Null + + + baymax55 +
+ Baymax55 +
+ hippo4j @@ -184,15 +191,15 @@ Hippo-4J 通过对 JDK 线程池增强,以及扩展三方框架底层线程池
杨镇涛
- + + Tliutao
Liutao
- - + monsterxxp @@ -242,13 +249,6 @@ Hippo-4J 通过对 JDK 线程池增强,以及扩展三方框架底层线程池 Serenity - - - baymax55 -
- Baymax55 -
- gewuwo From 656d508b35128525e6e490bb234e5be326962fa0 Mon Sep 17 00:00:00 2001 From: shanjianq <49084314+shanjianq@users.noreply.github.com> Date: Sun, 9 Oct 2022 14:32:26 +0800 Subject: [PATCH 3/7] finish thread pool config change verify (#776) * init code for verify module * init code for verify module * create application for config modify in thread pool manage * finish rejectModification * finish rejectModification * add todo * finish threadPoolManage accept * finish threadPoolManage accept * finish threadPoolManage config verify * formatting code * optimize ConfigModifyVerifyService * finish config modification verify * finish config modification verify * finish webConfig modification verify * finish webConfig modification verify * finish webConfig modification verify * finish threadPoolInstanceConfig modification verify * finish adapterThreadPoolConfig modification verify * finish adapterThreadPoolConfig modification verify * finish adapterThreadPoolConfig modification verify * optmize ConfigVerifyController * optmize ConfigVerifyController * optmize ConfigVerifyController * fix ConfigModifyVerifyReqDTO * fix bug * optimize verifyController * optimize verifyController * fix request param * finish modify application query page * finish modify application query page * finish modify application query detail * finish modify application query detail * finish thread pool config modification verify module * optimize accept modification logic * formatting code * fix bug * formatting code * formatting code * update sql file * add annotation * add annotation and formatting code * add annotation and formatting code * remove useless code * fix sql Co-authored-by: airoger --- .../constant/ConfigModifyTypeConstants.java | 41 ++++++ .../cn/hippo4j/common/constant/Constants.java | 2 + .../cn/hippo4j/common/enums/VerifyEnum.java | 58 ++++++++ hippo4j-config/pom.xml | 7 + .../config/controller/ConfigController.java | 20 ++- .../config/mapper/HisConfigVerifyMapper.java | 29 ++++ .../config/model/HisConfigVerifyInfo.java | 101 +++++++++++++ .../biz/adapter/ThreadPoolAdapterReqDTO.java | 5 + .../ConfigModificationQueryRespDTO.java | 97 ++++++++++++ .../threadpool/ConfigModifySaveReqDTO.java | 124 ++++++++++++++++ .../threadpool/ConfigModifyVerifyReqDTO.java | 138 ++++++++++++++++++ .../biz/ConfigModificationQueryService.java | 45 ++++++ .../biz/ConfigModificationVerifyService.java | 55 +++++++ ...stractConfigModificationVerifyService.java | 114 +++++++++++++++ ...olConfigModificationVerifyServiceImpl.java | 52 +++++++ .../ConfigModificationQueryServiceImpl.java | 62 ++++++++ ...ceConfigModificationVerifyServiceImpl.java | 53 +++++++ ...geConfigModificationVerifyServiceImpl.java | 53 +++++++ .../biz/impl/ThreadPoolServiceImpl.java | 31 ++-- ...olConfigModificationVerifyServiceImpl.java | 52 +++++++ ...ConfigModificationVerifyServiceChoose.java | 57 ++++++++ .../controller/ConfigVerifyController.java | 64 ++++++++ .../ThreadPoolAdapterController.java | 33 +++-- .../controller/ThreadPoolController.java | 45 +++--- .../console/model/WebThreadPoolReqDTO.java | 20 +++ .../console/model/WebThreadPoolRespDTO.java | 10 ++ hippo4j-server/conf/hippo4j_manager.sql | 23 +++ .../conf/sql-upgrade/1.4.2_upgrade.sql | 20 +++ .../sql-script/h2/hippo4j_manager.sql | 18 +++ .../sql-script/mysql/hippo4j_manager.sql | 22 +++ 30 files changed, 1413 insertions(+), 38 deletions(-) create mode 100644 hippo4j-common/src/main/java/cn/hippo4j/common/constant/ConfigModifyTypeConstants.java create mode 100644 hippo4j-common/src/main/java/cn/hippo4j/common/enums/VerifyEnum.java create mode 100644 hippo4j-config/src/main/java/cn/hippo4j/config/mapper/HisConfigVerifyMapper.java create mode 100644 hippo4j-config/src/main/java/cn/hippo4j/config/model/HisConfigVerifyInfo.java create mode 100644 hippo4j-config/src/main/java/cn/hippo4j/config/model/biz/threadpool/ConfigModificationQueryRespDTO.java create mode 100644 hippo4j-config/src/main/java/cn/hippo4j/config/model/biz/threadpool/ConfigModifySaveReqDTO.java create mode 100644 hippo4j-config/src/main/java/cn/hippo4j/config/model/biz/threadpool/ConfigModifyVerifyReqDTO.java create mode 100644 hippo4j-config/src/main/java/cn/hippo4j/config/service/biz/ConfigModificationQueryService.java create mode 100644 hippo4j-config/src/main/java/cn/hippo4j/config/service/biz/ConfigModificationVerifyService.java create mode 100644 hippo4j-config/src/main/java/cn/hippo4j/config/service/biz/impl/AbstractConfigModificationVerifyService.java create mode 100644 hippo4j-config/src/main/java/cn/hippo4j/config/service/biz/impl/AdapterThreadPoolConfigModificationVerifyServiceImpl.java create mode 100644 hippo4j-config/src/main/java/cn/hippo4j/config/service/biz/impl/ConfigModificationQueryServiceImpl.java create mode 100644 hippo4j-config/src/main/java/cn/hippo4j/config/service/biz/impl/ThreadPoolInstanceConfigModificationVerifyServiceImpl.java create mode 100644 hippo4j-config/src/main/java/cn/hippo4j/config/service/biz/impl/ThreadPoolManageConfigModificationVerifyServiceImpl.java create mode 100644 hippo4j-config/src/main/java/cn/hippo4j/config/service/biz/impl/WebThreadPoolConfigModificationVerifyServiceImpl.java create mode 100644 hippo4j-config/src/main/java/cn/hippo4j/config/verify/ConfigModificationVerifyServiceChoose.java create mode 100644 hippo4j-console/src/main/java/cn/hippo4j/console/controller/ConfigVerifyController.java diff --git a/hippo4j-common/src/main/java/cn/hippo4j/common/constant/ConfigModifyTypeConstants.java b/hippo4j-common/src/main/java/cn/hippo4j/common/constant/ConfigModifyTypeConstants.java new file mode 100644 index 00000000..84a8bf61 --- /dev/null +++ b/hippo4j-common/src/main/java/cn/hippo4j/common/constant/ConfigModifyTypeConstants.java @@ -0,0 +1,41 @@ +/* + * 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 cn.hippo4j.common.constant; + +public class ConfigModifyTypeConstants { + + /** + * Thread pool manager change + */ + public static final int THREAD_POOL_MANAGER = 1; + + /** + * Thread pool instance change + */ + public static final int THREAD_POOL_INSTANCE = 2; + + /** + * Web thread pool change + */ + public static final int WEB_THREAD_POOL = 3; + + /** + * Adapter thread pool change + */ + public static final int ADAPTER_THREAD_POOL = 4; +} diff --git a/hippo4j-common/src/main/java/cn/hippo4j/common/constant/Constants.java b/hippo4j-common/src/main/java/cn/hippo4j/common/constant/Constants.java index fb80954e..12e9ef5a 100644 --- a/hippo4j-common/src/main/java/cn/hippo4j/common/constant/Constants.java +++ b/hippo4j-common/src/main/java/cn/hippo4j/common/constant/Constants.java @@ -62,6 +62,8 @@ public class Constants { public static final String LISTENER_PATH = CONFIG_CONTROLLER_PATH + "/listener"; + public static final String VERIFY_PATH = CONFIG_CONTROLLER_PATH + "/verify"; + public static final String MONITOR_PATH = BASE_PATH + "/monitor"; public static final String REGISTER_ADAPTER_BASE_PATH = BASE_PATH + "/adapter/thread-pool"; diff --git a/hippo4j-common/src/main/java/cn/hippo4j/common/enums/VerifyEnum.java b/hippo4j-common/src/main/java/cn/hippo4j/common/enums/VerifyEnum.java new file mode 100644 index 00000000..d8f79afe --- /dev/null +++ b/hippo4j-common/src/main/java/cn/hippo4j/common/enums/VerifyEnum.java @@ -0,0 +1,58 @@ +/* + * 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 cn.hippo4j.common.enums; + +public enum VerifyEnum { + + /** + * unVerify + */ + TO_VERIFY(0, "待审核"), + + /** + * accept + */ + VERIFY_ACCEPT(1, "审核通过"), + + /** + * reject + */ + VERIFY_REJECT(2, "审核拒绝"), + + /** + * invalid + */ + VERIFY_INVALID(3, "失效"); + + private final Integer verifyStatus; + + private final String desc; + + VerifyEnum(Integer verifyStatus, String desc) { + this.verifyStatus = verifyStatus; + this.desc = desc; + } + + public String getDesc() { + return this.desc; + } + + public Integer getVerifyStatus() { + return this.verifyStatus; + } +} diff --git a/hippo4j-config/pom.xml b/hippo4j-config/pom.xml index e999ccdd..925e5f71 100644 --- a/hippo4j-config/pom.xml +++ b/hippo4j-config/pom.xml @@ -59,6 +59,12 @@ hippo4j-adapter-base + + cn.hippo4j + hippo4j-discovery + ${version} + + io.netty netty-all @@ -79,5 +85,6 @@ spring-boot-starter-test test + diff --git a/hippo4j-config/src/main/java/cn/hippo4j/config/controller/ConfigController.java b/hippo4j-config/src/main/java/cn/hippo4j/config/controller/ConfigController.java index 25543ee8..f4c48610 100644 --- a/hippo4j-config/src/main/java/cn/hippo4j/config/controller/ConfigController.java +++ b/hippo4j-config/src/main/java/cn/hippo4j/config/controller/ConfigController.java @@ -17,17 +17,22 @@ package cn.hippo4j.config.controller; +import cn.hippo4j.common.constant.ConfigModifyTypeConstants; import cn.hippo4j.common.constant.Constants; import cn.hippo4j.common.model.register.DynamicThreadPoolRegisterWrapper; +import cn.hippo4j.common.toolkit.BeanUtil; import cn.hippo4j.common.toolkit.StringUtil; +import cn.hippo4j.common.toolkit.UserContext; import cn.hippo4j.common.web.base.Result; import cn.hippo4j.common.web.base.Results; import cn.hippo4j.config.model.ConfigAllInfo; import cn.hippo4j.config.model.ConfigInfoBase; +import cn.hippo4j.config.model.biz.threadpool.ConfigModifySaveReqDTO; import cn.hippo4j.config.service.ConfigCacheService; import cn.hippo4j.config.service.ConfigServletInner; import cn.hippo4j.config.service.biz.ConfigService; import cn.hippo4j.config.toolkit.Md5ConfigUtil; +import cn.hippo4j.config.verify.ConfigModificationVerifyServiceChoose; import lombok.AllArgsConstructor; import lombok.SneakyThrows; import org.springframework.util.StringUtils; @@ -50,6 +55,8 @@ public class ConfigController { private final ConfigServletInner configServletInner; + private final ConfigModificationVerifyServiceChoose configModificationVerifyServiceChoose; + @GetMapping public Result detailConfigInfo(@RequestParam("tpId") String tpId, @RequestParam("itemId") String itemId, @@ -62,7 +69,18 @@ public class ConfigController { @PostMapping public Result publishConfig(@RequestParam(value = "identify", required = false) String identify, @RequestBody ConfigAllInfo config) { - configService.insertOrUpdate(identify, true, config); + if (UserContext.getUserRole().equals("ROLE_ADMIN")) { + configService.insertOrUpdate(identify, true, config); + } else { + ConfigModifySaveReqDTO modifySaveReqDTO = BeanUtil.convert(config, ConfigModifySaveReqDTO.class); + modifySaveReqDTO.setCorePoolSize(config.getCoreSize()); + modifySaveReqDTO.setMaximumPoolSize(config.getMaxSize()); + modifySaveReqDTO.setModifyUser(UserContext.getUserName()); + modifySaveReqDTO.setModifyAll(StringUtil.isEmpty(identify) ? true : false); + modifySaveReqDTO.setIdentify(identify); + modifySaveReqDTO.setType(ConfigModifyTypeConstants.THREAD_POOL_INSTANCE); + configModificationVerifyServiceChoose.choose(modifySaveReqDTO.getType()).saveConfigModifyApplication(modifySaveReqDTO); + } return Results.success(true); } diff --git a/hippo4j-config/src/main/java/cn/hippo4j/config/mapper/HisConfigVerifyMapper.java b/hippo4j-config/src/main/java/cn/hippo4j/config/mapper/HisConfigVerifyMapper.java new file mode 100644 index 00000000..c7c5b53e --- /dev/null +++ b/hippo4j-config/src/main/java/cn/hippo4j/config/mapper/HisConfigVerifyMapper.java @@ -0,0 +1,29 @@ +/* + * 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 cn.hippo4j.config.mapper; + +import cn.hippo4j.config.model.HisConfigVerifyInfo; +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import org.apache.ibatis.annotations.Mapper; + +/** + * his config verify info mapper + */ +@Mapper +public interface HisConfigVerifyMapper extends BaseMapper { +} diff --git a/hippo4j-config/src/main/java/cn/hippo4j/config/model/HisConfigVerifyInfo.java b/hippo4j-config/src/main/java/cn/hippo4j/config/model/HisConfigVerifyInfo.java new file mode 100644 index 00000000..4fdab92a --- /dev/null +++ b/hippo4j-config/src/main/java/cn/hippo4j/config/model/HisConfigVerifyInfo.java @@ -0,0 +1,101 @@ +/* + * 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 cn.hippo4j.config.model; + +import com.baomidou.mybatisplus.annotation.*; +import com.fasterxml.jackson.annotation.JsonIgnore; +import lombok.Data; + +import java.util.Date; + +/** + * His config verify info + */ +@Data +@TableName("his_config_verify") +public class HisConfigVerifyInfo { + + @TableId(type = IdType.AUTO) + private Long id; + + /** + * Change type + */ + private Integer type; + + /** + * Tenant id + */ + private String tenantId; + + /** + * Item id + */ + private String itemId; + + /** + * Thread pool id + */ + private String tpId; + + /** + * Thread pool mark + */ + private String mark; + + /** + * Thread pool instance identify + */ + private String identify; + + /** + * Config content + */ + private String content; + + /** + * Weather modify all thread pool instances + */ + private Boolean modifyAll = false; + + /** + * GmtCreate + */ + @TableField(fill = FieldFill.INSERT) + private Date gmtCreate; + + /** + * ModifyUserId + */ + private String modifyUser; + + /** + * Verify status + */ + private Integer verifyStatus; + + /** + * GmtVerify + */ + private Date gmtVerify; + + /** + * VerifyUser + */ + private String verifyUser; +} diff --git a/hippo4j-config/src/main/java/cn/hippo4j/config/model/biz/adapter/ThreadPoolAdapterReqDTO.java b/hippo4j-config/src/main/java/cn/hippo4j/config/model/biz/adapter/ThreadPoolAdapterReqDTO.java index e55b4571..55514186 100644 --- a/hippo4j-config/src/main/java/cn/hippo4j/config/model/biz/adapter/ThreadPoolAdapterReqDTO.java +++ b/hippo4j-config/src/main/java/cn/hippo4j/config/model/biz/adapter/ThreadPoolAdapterReqDTO.java @@ -66,4 +66,9 @@ public class ThreadPoolAdapterReqDTO { * Client address list */ private List clientAddressList; + + /** + * weather Modify all instances + */ + private Boolean modifyAll; } diff --git a/hippo4j-config/src/main/java/cn/hippo4j/config/model/biz/threadpool/ConfigModificationQueryRespDTO.java b/hippo4j-config/src/main/java/cn/hippo4j/config/model/biz/threadpool/ConfigModificationQueryRespDTO.java new file mode 100644 index 00000000..331db35e --- /dev/null +++ b/hippo4j-config/src/main/java/cn/hippo4j/config/model/biz/threadpool/ConfigModificationQueryRespDTO.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 cn.hippo4j.config.model.biz.threadpool; + +import com.fasterxml.jackson.annotation.JsonFormat; +import lombok.Data; + +import java.util.Date; + +/** + * Config modify query resp + */ +@Data +public class ConfigModificationQueryRespDTO { + + /** + * His_config_verify id + */ + private String id; + + /** + * Config modify type + */ + private Integer type; + + /** + * Thread pool mark + */ + private String mark; + + /** + * Tenant id + */ + private String tenantId; + + /** + * Item id + */ + private String itemId; + + /** + * Thread pool id + */ + private String tpId; + + /** + * Thread pool identify + */ + private String identify; + + /** + * Weather modify all instances + */ + private Boolean modifyAll; + + /** + * Modify user + */ + private String modifyUser; + + /** + * Verify status + */ + private Integer verifyStatus; + + /** + * GmtCreate + */ + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") + private Date gmtCreate; + + /** + * GmtVerify + */ + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") + private Date gmtVerify; + + /** + * Verify user + */ + private String verifyUser; +} diff --git a/hippo4j-config/src/main/java/cn/hippo4j/config/model/biz/threadpool/ConfigModifySaveReqDTO.java b/hippo4j-config/src/main/java/cn/hippo4j/config/model/biz/threadpool/ConfigModifySaveReqDTO.java new file mode 100644 index 00000000..035bd038 --- /dev/null +++ b/hippo4j-config/src/main/java/cn/hippo4j/config/model/biz/threadpool/ConfigModifySaveReqDTO.java @@ -0,0 +1,124 @@ +/* + * 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 cn.hippo4j.config.model.biz.threadpool; + +import lombok.Data; + +import javax.validation.constraints.Pattern; + +@Data +public class ConfigModifySaveReqDTO { + + /** + * Thread pool config change type. + */ + private Integer type; + + /** + * Thread pool instance id + */ + private String identify; + + /** + * Weather modify all instances + */ + private Boolean modifyAll = false; + + /** + * Tenant Id + */ + @Pattern(regexp = "^((?!\\+).)*$", message = "租户、项目、线程池 ID 包含+号") + private String tenantId; + + /** + * Thread pool id + */ + @Pattern(regexp = "^((?!\\+).)*$", message = "租户、项目、线程池 ID 包含+号") + private String tpId; + + /** + * Item id + */ + @Pattern(regexp = "^((?!\\+).)*$", message = "租户、项目、线程池 ID 包含+号") + private String itemId; + + /** + * Thread pool mark + */ + private String mark; + + /** + * Core pool size + */ + private Integer corePoolSize; + + /** + * Maximum pool size + */ + private Integer maximumPoolSize; + + /** + * Queue type + */ + private Integer queueType; + + /** + * Capacity + */ + private Integer capacity; + + /** + * Keep alive time + */ + private Integer keepAliveTime; + + /** + * Execute time out + */ + private Long executeTimeOut; + + /** + * Is alarm + */ + private Integer isAlarm; + + /** + * Capacity alarm + */ + private Integer capacityAlarm; + + /** + * Liveness alarm + */ + private Integer livenessAlarm; + + /** + * Rejected type + */ + private Integer rejectedType; + + /** + * Allow core thread timeout + */ + private Integer allowCoreThreadTimeOut; + + /** + * ModifyUser + */ + private String modifyUser; +} diff --git a/hippo4j-config/src/main/java/cn/hippo4j/config/model/biz/threadpool/ConfigModifyVerifyReqDTO.java b/hippo4j-config/src/main/java/cn/hippo4j/config/model/biz/threadpool/ConfigModifyVerifyReqDTO.java new file mode 100644 index 00000000..946e4764 --- /dev/null +++ b/hippo4j-config/src/main/java/cn/hippo4j/config/model/biz/threadpool/ConfigModifyVerifyReqDTO.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 cn.hippo4j.config.model.biz.threadpool; + +import com.fasterxml.jackson.annotation.JsonAlias; +import lombok.Data; + +import java.util.List; + +/** + * Config modify verify dto + */ +@Data +public class ConfigModifyVerifyReqDTO { + + /** + * His config verify id + */ + private String id; + + /** + * Config verify type + */ + private Integer type; + + /** + * Tenant id + */ + private String tenantId; + + /** + * Item id + */ + private String itemId; + + /** + * Instance identify + */ + private String identify; + + /** + * Adapter thread pool mark + */ + private String mark; + + /** + * Adapter thread pool key + */ + private String threadPoolKey; + + /** + * Thread pool id + */ + @JsonAlias("threadPoolId") + private String tpId; + + /** + * Weather modify all instances + */ + private Boolean modifyAll; + + /** + * Weather accept config modification + */ + private Boolean accept; + + /** + * Core pool size + */ + private Integer corePoolSize; + + /** + * Maximum pool size + */ + private Integer maximumPoolSize; + + /** + * Queue type + */ + private Integer queueType; + + /** + * Capacity + */ + private Integer capacity; + + /** + * Keep alive time + */ + private Integer keepAliveTime; + + /** + * Execute time out + */ + private Long executeTimeOut; + + /** + * Rejected type + */ + private Integer rejectedType; + + /** + * Is alarm + */ + private Integer isAlarm; + + /** + * Capacity alarm + */ + private Integer capacityAlarm; + + /** + * Liveness alarm + */ + @JsonAlias("activeAlarm") + private Integer livenessAlarm; + + /** + * Allow core thread timeout + */ + private Integer allowCoreThreadTimeOut; + +} diff --git a/hippo4j-config/src/main/java/cn/hippo4j/config/service/biz/ConfigModificationQueryService.java b/hippo4j-config/src/main/java/cn/hippo4j/config/service/biz/ConfigModificationQueryService.java new file mode 100644 index 00000000..2f8d3f63 --- /dev/null +++ b/hippo4j-config/src/main/java/cn/hippo4j/config/service/biz/ConfigModificationQueryService.java @@ -0,0 +1,45 @@ +/* + * 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 cn.hippo4j.config.service.biz; + +import cn.hippo4j.common.model.ThreadPoolParameterInfo; +import cn.hippo4j.config.model.biz.threadpool.ConfigModificationQueryRespDTO; +import cn.hippo4j.config.model.biz.threadpool.ThreadPoolQueryReqDTO; +import com.baomidou.mybatisplus.core.metadata.IPage; + +/** + * Config modification application query service. + */ +public interface ConfigModificationQueryService { + + /** + * Query config modification application page. + * + * @param reqDTO + * @return + */ + IPage queryApplicationPage(ThreadPoolQueryReqDTO reqDTO); + + /** + * Query config modification detail by application id. + * + * @param id + * @return + */ + ThreadPoolParameterInfo queryApplicationDetail(Long id); +} diff --git a/hippo4j-config/src/main/java/cn/hippo4j/config/service/biz/ConfigModificationVerifyService.java b/hippo4j-config/src/main/java/cn/hippo4j/config/service/biz/ConfigModificationVerifyService.java new file mode 100644 index 00000000..633df590 --- /dev/null +++ b/hippo4j-config/src/main/java/cn/hippo4j/config/service/biz/ConfigModificationVerifyService.java @@ -0,0 +1,55 @@ +/* + * 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 cn.hippo4j.config.service.biz; + +import cn.hippo4j.config.model.biz.threadpool.ConfigModifySaveReqDTO; +import cn.hippo4j.config.model.biz.threadpool.ConfigModifyVerifyReqDTO; + +/** + * Config modification verify service. + */ +public interface ConfigModificationVerifyService { + + /** + * Get type. + * + * @return + */ + Integer type(); + + /** + * Save config change application. + * + * @param reqDTO + */ + void saveConfigModifyApplication(ConfigModifySaveReqDTO reqDTO); + + /** + * Reject config modification. + * + * @param reqDTO + */ + void rejectModification(ConfigModifyVerifyReqDTO reqDTO); + + /** + * Accept config modification. + * + * @param reqDTO + */ + void acceptModification(ConfigModifyVerifyReqDTO reqDTO); +} diff --git a/hippo4j-config/src/main/java/cn/hippo4j/config/service/biz/impl/AbstractConfigModificationVerifyService.java b/hippo4j-config/src/main/java/cn/hippo4j/config/service/biz/impl/AbstractConfigModificationVerifyService.java new file mode 100644 index 00000000..c60bc43b --- /dev/null +++ b/hippo4j-config/src/main/java/cn/hippo4j/config/service/biz/impl/AbstractConfigModificationVerifyService.java @@ -0,0 +1,114 @@ +/* + * 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 cn.hippo4j.config.service.biz.impl; + +import cn.hippo4j.common.enums.VerifyEnum; +import cn.hippo4j.common.model.InstanceInfo; +import cn.hippo4j.common.toolkit.BeanUtil; +import cn.hippo4j.common.toolkit.ConditionUtil; +import cn.hippo4j.common.toolkit.JSONUtil; +import cn.hippo4j.common.toolkit.UserContext; +import cn.hippo4j.config.mapper.HisConfigVerifyMapper; +import cn.hippo4j.config.model.HisConfigVerifyInfo; +import cn.hippo4j.config.model.biz.threadpool.ConfigModifySaveReqDTO; +import cn.hippo4j.config.model.biz.threadpool.ConfigModifyVerifyReqDTO; +import cn.hippo4j.config.service.biz.ConfigModificationVerifyService; +import cn.hippo4j.discovery.core.BaseInstanceRegistry; +import cn.hippo4j.discovery.core.Lease; +import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; + +import javax.annotation.Resource; +import java.util.ArrayList; +import java.util.Date; +import java.util.List; + +/** + * Abstract config modification verify service. + */ +public abstract class AbstractConfigModificationVerifyService implements ConfigModificationVerifyService { + + @Resource + protected HisConfigVerifyMapper hisConfigVerifyMapper; + + @Resource + private BaseInstanceRegistry baseInstanceRegistry; + + @Override + public void saveConfigModifyApplication(ConfigModifySaveReqDTO reqDTO) { + HisConfigVerifyInfo hisConfigVerifyInfo = BeanUtil.convert(reqDTO, HisConfigVerifyInfo.class); + hisConfigVerifyInfo.setContent(JSONUtil.toJSONString(reqDTO)); + hisConfigVerifyInfo.setVerifyStatus(VerifyEnum.TO_VERIFY.getVerifyStatus()); + hisConfigVerifyMapper.insert(hisConfigVerifyInfo); + } + + @Override + public void rejectModification(ConfigModifyVerifyReqDTO reqDTO) { + LambdaUpdateWrapper updateWrapper = new LambdaUpdateWrapper() + .eq(HisConfigVerifyInfo::getId, Long.parseLong(reqDTO.getId())) + .set(HisConfigVerifyInfo::getVerifyStatus, VerifyEnum.VERIFY_REJECT.getVerifyStatus()) + .set(HisConfigVerifyInfo::getGmtVerify, new Date()) + .set(HisConfigVerifyInfo::getVerifyUser, UserContext.getUserName()); + hisConfigVerifyMapper.update(null, updateWrapper); + } + + public void acceptModification(ConfigModifyVerifyReqDTO reqDTO) { + updateThreadPoolParameter(reqDTO); + LambdaUpdateWrapper updateWrapper = new LambdaUpdateWrapper() + .eq(HisConfigVerifyInfo::getId, Long.parseLong(reqDTO.getId())) + .set(HisConfigVerifyInfo::getVerifyStatus, VerifyEnum.VERIFY_ACCEPT.getVerifyStatus()) + .set(HisConfigVerifyInfo::getGmtVerify, new Date()) + .set(HisConfigVerifyInfo::getVerifyUser, UserContext.getUserName()); + hisConfigVerifyMapper.update(null, updateWrapper); + Date gmtVerify = hisConfigVerifyMapper.selectById(reqDTO.getId()).getGmtVerify(); + LambdaUpdateWrapper invalidUpdateWrapper = new LambdaUpdateWrapper() + .eq(HisConfigVerifyInfo::getType, reqDTO.getType()) + .eq(reqDTO.getTenantId() != null, HisConfigVerifyInfo::getTenantId, reqDTO.getTenantId()) + .eq(reqDTO.getItemId() != null, HisConfigVerifyInfo::getItemId, reqDTO.getItemId()) + .eq(reqDTO.getTpId() != null, HisConfigVerifyInfo::getTpId, reqDTO.getTpId()) + .and(reqDTO.getIdentify() != null, wrapper -> wrapper.eq(HisConfigVerifyInfo::getIdentify, reqDTO.getIdentify()).or().eq(HisConfigVerifyInfo::getModifyAll, true)) + .lt(HisConfigVerifyInfo::getGmtVerify, gmtVerify) + .set(HisConfigVerifyInfo::getVerifyStatus, VerifyEnum.VERIFY_INVALID.getVerifyStatus()); + hisConfigVerifyMapper.update(null, invalidUpdateWrapper); + } + + /** + * Get client address. + * + * @param reqDTO + * @return + */ + protected List getClientAddress(ConfigModifyVerifyReqDTO reqDTO) { + List clientAddressList = new ArrayList<>(); + List> leases = baseInstanceRegistry.listInstance(reqDTO.getItemId()); + ConditionUtil + .condition(reqDTO.getModifyAll(), + () -> leases.forEach(lease -> clientAddressList.add(lease.getHolder().getCallBackUrl())), + () -> clientAddressList.add( + leases.stream() + .filter(lease -> lease.getHolder().getIdentify().equals(reqDTO.getIdentify())).findAny().orElseThrow(() -> new RuntimeException("该线程池实例不存在")).getHolder() + .getCallBackUrl())); + return clientAddressList; + } + + /** + * Update thread pool parameter. + * + * @param reqDTO + */ + protected abstract void updateThreadPoolParameter(ConfigModifyVerifyReqDTO reqDTO); +} diff --git a/hippo4j-config/src/main/java/cn/hippo4j/config/service/biz/impl/AdapterThreadPoolConfigModificationVerifyServiceImpl.java b/hippo4j-config/src/main/java/cn/hippo4j/config/service/biz/impl/AdapterThreadPoolConfigModificationVerifyServiceImpl.java new file mode 100644 index 00000000..6178da1f --- /dev/null +++ b/hippo4j-config/src/main/java/cn/hippo4j/config/service/biz/impl/AdapterThreadPoolConfigModificationVerifyServiceImpl.java @@ -0,0 +1,52 @@ +/* + * 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 cn.hippo4j.config.service.biz.impl; + +import cn.hippo4j.common.constant.ConfigModifyTypeConstants; +import cn.hippo4j.common.toolkit.JSONUtil; +import cn.hippo4j.config.model.biz.threadpool.ConfigModifyVerifyReqDTO; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Service; +import org.springframework.web.client.RestTemplate; + +/** + * Adapter thread pool config modification verify service impl. + */ +@Slf4j +@Service +public class AdapterThreadPoolConfigModificationVerifyServiceImpl extends AbstractConfigModificationVerifyService { + + private final RestTemplate restTemplate = new RestTemplate(); + + @Override + public Integer type() { + return ConfigModifyTypeConstants.ADAPTER_THREAD_POOL; + } + + @Override + protected void updateThreadPoolParameter(ConfigModifyVerifyReqDTO reqDTO) { + for (String each : getClientAddress(reqDTO)) { + String urlString = new StringBuilder() + .append("http://") + .append(each) + .append("/adapter/thread-pool/update") + .toString(); + restTemplate.postForObject(urlString, JSONUtil.toJSONString(reqDTO), Object.class); + } + } +} diff --git a/hippo4j-config/src/main/java/cn/hippo4j/config/service/biz/impl/ConfigModificationQueryServiceImpl.java b/hippo4j-config/src/main/java/cn/hippo4j/config/service/biz/impl/ConfigModificationQueryServiceImpl.java new file mode 100644 index 00000000..c3cbcd3d --- /dev/null +++ b/hippo4j-config/src/main/java/cn/hippo4j/config/service/biz/impl/ConfigModificationQueryServiceImpl.java @@ -0,0 +1,62 @@ +/* + * 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 cn.hippo4j.config.service.biz.impl; + +import cn.hippo4j.common.model.ThreadPoolParameterInfo; +import cn.hippo4j.common.toolkit.BeanUtil; +import cn.hippo4j.common.toolkit.JSONUtil; +import cn.hippo4j.config.mapper.HisConfigVerifyMapper; +import cn.hippo4j.config.model.HisConfigVerifyInfo; +import cn.hippo4j.config.model.biz.threadpool.ConfigModificationQueryRespDTO; +import cn.hippo4j.config.model.biz.threadpool.ThreadPoolQueryReqDTO; +import cn.hippo4j.config.service.biz.ConfigModificationQueryService; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.baomidou.mybatisplus.core.toolkit.StringUtils; +import com.baomidou.mybatisplus.core.toolkit.Wrappers; +import org.springframework.stereotype.Service; + +import javax.annotation.Resource; + +/** + * Config modification query service impl + */ +@Service +public class ConfigModificationQueryServiceImpl implements ConfigModificationQueryService { + + @Resource + private HisConfigVerifyMapper hisConfigVerifyMapper; + + @Override + public IPage queryApplicationPage(ThreadPoolQueryReqDTO reqDTO) { + LambdaQueryWrapper wrapper = Wrappers.lambdaQuery(HisConfigVerifyInfo.class) + .eq(!StringUtils.isBlank(reqDTO.getTenantId()), HisConfigVerifyInfo::getTenantId, reqDTO.getTenantId()) + .eq(!StringUtils.isBlank(reqDTO.getItemId()), HisConfigVerifyInfo::getItemId, reqDTO.getItemId()) + .orderByDesc(HisConfigVerifyInfo::getGmtCreate); + return hisConfigVerifyMapper.selectPage(reqDTO, wrapper).convert(each -> BeanUtil.convert(each, ConfigModificationQueryRespDTO.class)); + } + + @Override + public ThreadPoolParameterInfo queryApplicationDetail(Long id) { + HisConfigVerifyInfo hisConfigVerifyInfo = hisConfigVerifyMapper.selectById(id); + ThreadPoolParameterInfo poolParameterInfo = JSONUtil.parseObject(hisConfigVerifyInfo.getContent(), ThreadPoolParameterInfo.class); + poolParameterInfo.setCorePoolSize(poolParameterInfo.corePoolSizeAdapt()); + poolParameterInfo.setMaximumPoolSize(poolParameterInfo.maximumPoolSizeAdapt()); + return poolParameterInfo; + } +} diff --git a/hippo4j-config/src/main/java/cn/hippo4j/config/service/biz/impl/ThreadPoolInstanceConfigModificationVerifyServiceImpl.java b/hippo4j-config/src/main/java/cn/hippo4j/config/service/biz/impl/ThreadPoolInstanceConfigModificationVerifyServiceImpl.java new file mode 100644 index 00000000..085cc70d --- /dev/null +++ b/hippo4j-config/src/main/java/cn/hippo4j/config/service/biz/impl/ThreadPoolInstanceConfigModificationVerifyServiceImpl.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 cn.hippo4j.config.service.biz.impl; + +import cn.hippo4j.common.constant.ConfigModifyTypeConstants; +import cn.hippo4j.common.toolkit.BeanUtil; +import cn.hippo4j.config.model.ConfigAllInfo; +import cn.hippo4j.config.model.biz.threadpool.ConfigModifyVerifyReqDTO; +import cn.hippo4j.config.service.biz.ConfigService; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Service; + +import javax.annotation.Resource; + +/** + * Thread pool instance config modification verify service impl. + */ +@Slf4j +@Service +public class ThreadPoolInstanceConfigModificationVerifyServiceImpl extends AbstractConfigModificationVerifyService { + + @Resource + private ConfigService configService; + + @Override + public Integer type() { + return ConfigModifyTypeConstants.THREAD_POOL_INSTANCE; + } + + @Override + protected void updateThreadPoolParameter(ConfigModifyVerifyReqDTO reqDTO) { + ConfigAllInfo config = BeanUtil.convert(reqDTO, ConfigAllInfo.class); + config.setCoreSize(reqDTO.getCorePoolSize()); + config.setMaxSize(reqDTO.getMaximumPoolSize()); + configService.insertOrUpdate(reqDTO.getIdentify(), true, config); + } + +} diff --git a/hippo4j-config/src/main/java/cn/hippo4j/config/service/biz/impl/ThreadPoolManageConfigModificationVerifyServiceImpl.java b/hippo4j-config/src/main/java/cn/hippo4j/config/service/biz/impl/ThreadPoolManageConfigModificationVerifyServiceImpl.java new file mode 100644 index 00000000..1b569857 --- /dev/null +++ b/hippo4j-config/src/main/java/cn/hippo4j/config/service/biz/impl/ThreadPoolManageConfigModificationVerifyServiceImpl.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 cn.hippo4j.config.service.biz.impl; + +import cn.hippo4j.common.constant.ConfigModifyTypeConstants; +import cn.hippo4j.common.toolkit.BeanUtil; +import cn.hippo4j.config.model.biz.threadpool.ConfigModifyVerifyReqDTO; +import cn.hippo4j.config.model.biz.threadpool.ThreadPoolSaveOrUpdateReqDTO; +import cn.hippo4j.config.service.biz.ThreadPoolService; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Service; + +import javax.annotation.Resource; + +/** + * Thread pool manager config modification verify service impl. + */ +@Slf4j +@Service +public class ThreadPoolManageConfigModificationVerifyServiceImpl extends AbstractConfigModificationVerifyService { + + @Resource + private ThreadPoolService threadPoolService; + + @Override + public Integer type() { + return ConfigModifyTypeConstants.THREAD_POOL_MANAGER; + } + + @Override + public void updateThreadPoolParameter(ConfigModifyVerifyReqDTO reqDTO) { + ThreadPoolSaveOrUpdateReqDTO saveOrUpdateReqDTO = BeanUtil.convert(reqDTO, ThreadPoolSaveOrUpdateReqDTO.class); + saveOrUpdateReqDTO.setCoreSize(reqDTO.getCorePoolSize()); + saveOrUpdateReqDTO.setMaxSize(reqDTO.getMaximumPoolSize()); + threadPoolService.saveOrUpdateThreadPoolConfig(null, saveOrUpdateReqDTO); + } + +} diff --git a/hippo4j-config/src/main/java/cn/hippo4j/config/service/biz/impl/ThreadPoolServiceImpl.java b/hippo4j-config/src/main/java/cn/hippo4j/config/service/biz/impl/ThreadPoolServiceImpl.java index 8c58e935..d64c7698 100644 --- a/hippo4j-config/src/main/java/cn/hippo4j/config/service/biz/impl/ThreadPoolServiceImpl.java +++ b/hippo4j-config/src/main/java/cn/hippo4j/config/service/biz/impl/ThreadPoolServiceImpl.java @@ -17,20 +17,19 @@ package cn.hippo4j.config.service.biz.impl; +import cn.hippo4j.common.constant.ConfigModifyTypeConstants; import cn.hippo4j.common.enums.DelEnum; +import cn.hippo4j.common.toolkit.BeanUtil; import cn.hippo4j.common.toolkit.JSONUtil; import cn.hippo4j.common.toolkit.UserContext; import cn.hippo4j.config.mapper.ConfigInfoMapper; import cn.hippo4j.config.model.ConfigAllInfo; import cn.hippo4j.config.model.LogRecordInfo; -import cn.hippo4j.config.model.biz.threadpool.ThreadPoolDelReqDTO; -import cn.hippo4j.config.model.biz.threadpool.ThreadPoolQueryReqDTO; -import cn.hippo4j.config.model.biz.threadpool.ThreadPoolRespDTO; -import cn.hippo4j.config.model.biz.threadpool.ThreadPoolSaveOrUpdateReqDTO; +import cn.hippo4j.config.model.biz.threadpool.*; import cn.hippo4j.config.service.biz.ConfigService; import cn.hippo4j.config.service.biz.OperationLogService; import cn.hippo4j.config.service.biz.ThreadPoolService; -import cn.hippo4j.common.toolkit.BeanUtil; +import cn.hippo4j.config.verify.ConfigModificationVerifyServiceChoose; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.core.toolkit.StringUtils; @@ -55,6 +54,8 @@ public class ThreadPoolServiceImpl implements ThreadPoolService { private final OperationLogService operationLogService; + private final ConfigModificationVerifyServiceChoose configModificationVerifyServiceChoose; + @Override public IPage queryThreadPoolPage(ThreadPoolQueryReqDTO reqDTO) { LambdaQueryWrapper wrapper = Wrappers.lambdaQuery(ConfigAllInfo.class) @@ -82,10 +83,22 @@ public class ThreadPoolServiceImpl implements ThreadPoolService { @Override public void saveOrUpdateThreadPoolConfig(String identify, ThreadPoolSaveOrUpdateReqDTO reqDTO) { - ConfigAllInfo configAllInfo = BeanUtil.convert(reqDTO, ConfigAllInfo.class); - Long executeTimeOut = Objects.equals(configAllInfo.getExecuteTimeOut(), 0L) ? null : configAllInfo.getExecuteTimeOut(); - configAllInfo.setExecuteTimeOut(executeTimeOut); - configService.insertOrUpdate(identify, false, configAllInfo); + // TODO to optimize the Role of judgment + if (UserContext.getUserRole().equals("ROLE_ADMIN")) { + ConfigAllInfo configAllInfo = BeanUtil.convert(reqDTO, ConfigAllInfo.class); + Long executeTimeOut = Objects.equals(configAllInfo.getExecuteTimeOut(), 0L) ? null : configAllInfo.getExecuteTimeOut(); + configAllInfo.setExecuteTimeOut(executeTimeOut); + configService.insertOrUpdate(identify, false, configAllInfo); + } else { + ConfigModifySaveReqDTO modifySaveReqDTO = BeanUtil.convert(reqDTO, ConfigModifySaveReqDTO.class); + modifySaveReqDTO.setCorePoolSize(reqDTO.getCoreSize()); + modifySaveReqDTO.setMaximumPoolSize(reqDTO.getMaxSize()); + modifySaveReqDTO.setModifyUser(UserContext.getUserName()); + modifySaveReqDTO.setModifyAll(false); + modifySaveReqDTO.setType(ConfigModifyTypeConstants.THREAD_POOL_MANAGER); + configModificationVerifyServiceChoose.choose(modifySaveReqDTO.getType()).saveConfigModifyApplication(modifySaveReqDTO); + } + } @Override diff --git a/hippo4j-config/src/main/java/cn/hippo4j/config/service/biz/impl/WebThreadPoolConfigModificationVerifyServiceImpl.java b/hippo4j-config/src/main/java/cn/hippo4j/config/service/biz/impl/WebThreadPoolConfigModificationVerifyServiceImpl.java new file mode 100644 index 00000000..29712765 --- /dev/null +++ b/hippo4j-config/src/main/java/cn/hippo4j/config/service/biz/impl/WebThreadPoolConfigModificationVerifyServiceImpl.java @@ -0,0 +1,52 @@ +/* + * 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 cn.hippo4j.config.service.biz.impl; + +import cn.hippo4j.common.constant.ConfigModifyTypeConstants; +import cn.hippo4j.common.toolkit.JSONUtil; +import cn.hippo4j.config.model.biz.threadpool.ConfigModifyVerifyReqDTO; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Service; +import org.springframework.web.client.RestTemplate; + +/** + * Web thread pool config modification verify service impl. + */ +@Slf4j +@Service +public class WebThreadPoolConfigModificationVerifyServiceImpl extends AbstractConfigModificationVerifyService { + + private final RestTemplate restTemplate = new RestTemplate(); + + @Override + public Integer type() { + return ConfigModifyTypeConstants.WEB_THREAD_POOL; + } + + @Override + protected void updateThreadPoolParameter(ConfigModifyVerifyReqDTO reqDTO) { + for (String each : getClientAddress(reqDTO)) { + String urlString = new StringBuilder() + .append("http://") + .append(each) + .append("/web/update/pool") + .toString(); + restTemplate.postForObject(urlString, JSONUtil.toJSONString(reqDTO), Object.class); + } + } +} diff --git a/hippo4j-config/src/main/java/cn/hippo4j/config/verify/ConfigModificationVerifyServiceChoose.java b/hippo4j-config/src/main/java/cn/hippo4j/config/verify/ConfigModificationVerifyServiceChoose.java new file mode 100644 index 00000000..98769559 --- /dev/null +++ b/hippo4j-config/src/main/java/cn/hippo4j/config/verify/ConfigModificationVerifyServiceChoose.java @@ -0,0 +1,57 @@ +/* + * 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 cn.hippo4j.config.verify; + +import cn.hippo4j.common.config.ApplicationContextHolder; +import cn.hippo4j.common.constant.ConfigModifyTypeConstants; +import cn.hippo4j.config.service.biz.ConfigModificationVerifyService; +import org.springframework.boot.CommandLineRunner; +import org.springframework.stereotype.Component; + +import java.util.HashMap; +import java.util.Map; + +/** + * Config change verify service choose + */ +@Component +public class ConfigModificationVerifyServiceChoose implements CommandLineRunner { + + /** + * Storage config change verify service container. + */ + private Map configChangeVerifyServiceChooseMap = new HashMap<>(); + + /** + * Choose by type. + * + * @param type {@link ConfigModifyTypeConstants} + * @return + */ + public ConfigModificationVerifyService choose(Integer type) { + ConfigModificationVerifyService verifyService = configChangeVerifyServiceChooseMap.get(type); + return verifyService; + } + + @Override + public void run(String... args) throws Exception { + Map configChangeVerifyServiceMap = + ApplicationContextHolder.getBeansOfType(ConfigModificationVerifyService.class); + configChangeVerifyServiceMap.values().forEach(each -> configChangeVerifyServiceChooseMap.put(each.type(), each)); + } +} diff --git a/hippo4j-console/src/main/java/cn/hippo4j/console/controller/ConfigVerifyController.java b/hippo4j-console/src/main/java/cn/hippo4j/console/controller/ConfigVerifyController.java new file mode 100644 index 00000000..313af1a0 --- /dev/null +++ b/hippo4j-console/src/main/java/cn/hippo4j/console/controller/ConfigVerifyController.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 cn.hippo4j.console.controller; + +import cn.hippo4j.common.constant.Constants; +import cn.hippo4j.common.model.ThreadPoolParameterInfo; +import cn.hippo4j.common.toolkit.ConditionUtil; +import cn.hippo4j.common.web.base.Result; +import cn.hippo4j.common.web.base.Results; +import cn.hippo4j.config.model.biz.threadpool.ConfigModificationQueryRespDTO; +import cn.hippo4j.config.model.biz.threadpool.ConfigModifyVerifyReqDTO; +import cn.hippo4j.config.model.biz.threadpool.ThreadPoolQueryReqDTO; +import cn.hippo4j.config.service.biz.ConfigModificationQueryService; +import cn.hippo4j.config.service.biz.ConfigModificationVerifyService; +import cn.hippo4j.config.verify.ConfigModificationVerifyServiceChoose; +import com.baomidou.mybatisplus.core.metadata.IPage; +import lombok.AllArgsConstructor; +import org.springframework.web.bind.annotation.*; + +@RestController +@AllArgsConstructor +@RequestMapping(Constants.VERIFY_PATH) +public class ConfigVerifyController { + + private final ConfigModificationVerifyServiceChoose serviceChoose; + + private final ConfigModificationQueryService queryService; + + @PostMapping + public Result verifyConfigModification(@RequestBody ConfigModifyVerifyReqDTO reqDTO) { + ConfigModificationVerifyService modifyVerifyService = serviceChoose.choose(reqDTO.getType()); + ConditionUtil + .condition(reqDTO.getAccept(), + () -> modifyVerifyService.acceptModification(reqDTO), + () -> modifyVerifyService.rejectModification(reqDTO)); + return Results.success(); + } + + @PostMapping("/query/application/page") + public Result> modificationApplicationPage(@RequestBody ThreadPoolQueryReqDTO reqDTO) { + return Results.success(queryService.queryApplicationPage(reqDTO)); + } + + @GetMapping("/query/application/detail") + public Result modificationApplicationDetail(@RequestParam("id") String id) { + return Results.success(queryService.queryApplicationDetail(Long.parseLong(id))); + } + +} diff --git a/hippo4j-console/src/main/java/cn/hippo4j/console/controller/ThreadPoolAdapterController.java b/hippo4j-console/src/main/java/cn/hippo4j/console/controller/ThreadPoolAdapterController.java index 8937a004..a30b6d07 100644 --- a/hippo4j-console/src/main/java/cn/hippo4j/console/controller/ThreadPoolAdapterController.java +++ b/hippo4j-console/src/main/java/cn/hippo4j/console/controller/ThreadPoolAdapterController.java @@ -17,12 +17,17 @@ package cn.hippo4j.console.controller; +import cn.hippo4j.common.constant.ConfigModifyTypeConstants; +import cn.hippo4j.common.toolkit.BeanUtil; import cn.hippo4j.common.toolkit.JSONUtil; +import cn.hippo4j.common.toolkit.UserContext; import cn.hippo4j.common.web.base.Result; import cn.hippo4j.common.web.base.Results; import cn.hippo4j.config.model.biz.adapter.ThreadPoolAdapterReqDTO; import cn.hippo4j.config.model.biz.adapter.ThreadPoolAdapterRespDTO; +import cn.hippo4j.config.model.biz.threadpool.ConfigModifySaveReqDTO; import cn.hippo4j.config.service.ThreadPoolAdapterService; +import cn.hippo4j.config.verify.ConfigModificationVerifyServiceChoose; import lombok.AllArgsConstructor; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PostMapping; @@ -30,11 +35,9 @@ import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RestController; import org.springframework.web.client.RestTemplate; -import java.util.HashMap; import java.util.List; import java.util.Set; -import static cn.hippo4j.common.constant.Constants.HTTP_EXECUTE_TIMEOUT; import static cn.hippo4j.common.constant.Constants.REGISTER_ADAPTER_BASE_PATH; /** @@ -46,6 +49,8 @@ public class ThreadPoolAdapterController { private final ThreadPoolAdapterService threadPoolAdapterService; + private final ConfigModificationVerifyServiceChoose configModificationVerifyServiceChoose; + private final RestTemplate restTemplate = new RestTemplate(); @GetMapping(REGISTER_ADAPTER_BASE_PATH + "/query") @@ -62,13 +67,23 @@ public class ThreadPoolAdapterController { @PostMapping(REGISTER_ADAPTER_BASE_PATH + "/update") public Result updateAdapterThreadPool(@RequestBody ThreadPoolAdapterReqDTO requestParameter) { - for (String each : requestParameter.getClientAddressList()) { - String urlString = new StringBuilder() - .append("http://") - .append(each) - .append("/adapter/thread-pool/update") - .toString(); - restTemplate.postForObject(urlString, JSONUtil.toJSONString(requestParameter), Object.class); + if (UserContext.getUserRole().equals("ROLE_ADMIN")) { + for (String each : requestParameter.getClientAddressList()) { + String urlString = new StringBuilder() + .append("http://") + .append(each) + .append("/adapter/thread-pool/update") + .toString(); + restTemplate.postForObject(urlString, JSONUtil.toJSONString(requestParameter), Object.class); + } + } else { + ConfigModifySaveReqDTO modifySaveReqDTO = BeanUtil.convert(requestParameter, ConfigModifySaveReqDTO.class); + modifySaveReqDTO.setModifyUser(UserContext.getUserName()); + modifySaveReqDTO.setTenantId(requestParameter.getTenant()); + modifySaveReqDTO.setItemId(requestParameter.getItem()); + modifySaveReqDTO.setTpId(requestParameter.getThreadPoolKey()); + modifySaveReqDTO.setType(ConfigModifyTypeConstants.ADAPTER_THREAD_POOL); + configModificationVerifyServiceChoose.choose(modifySaveReqDTO.getType()).saveConfigModifyApplication(modifySaveReqDTO); } return Results.success(); } diff --git a/hippo4j-console/src/main/java/cn/hippo4j/console/controller/ThreadPoolController.java b/hippo4j-console/src/main/java/cn/hippo4j/console/controller/ThreadPoolController.java index f0da644b..09909cf8 100644 --- a/hippo4j-console/src/main/java/cn/hippo4j/console/controller/ThreadPoolController.java +++ b/hippo4j-console/src/main/java/cn/hippo4j/console/controller/ThreadPoolController.java @@ -17,22 +17,18 @@ package cn.hippo4j.console.controller; +import cn.hippo4j.common.constant.ConfigModifyTypeConstants; import cn.hippo4j.common.constant.Constants; import cn.hippo4j.common.model.InstanceInfo; -import cn.hippo4j.common.toolkit.CollectionUtil; -import cn.hippo4j.common.toolkit.JSONUtil; -import cn.hippo4j.common.toolkit.StringUtil; +import cn.hippo4j.common.toolkit.*; import cn.hippo4j.common.web.base.Result; import cn.hippo4j.common.web.base.Results; import cn.hippo4j.common.web.exception.ErrorCodeEnum; import cn.hippo4j.config.model.CacheItem; -import cn.hippo4j.config.model.biz.threadpool.ThreadPoolDelReqDTO; -import cn.hippo4j.config.model.biz.threadpool.ThreadPoolQueryReqDTO; -import cn.hippo4j.config.model.biz.threadpool.ThreadPoolRespDTO; -import cn.hippo4j.config.model.biz.threadpool.ThreadPoolSaveOrUpdateReqDTO; +import cn.hippo4j.config.model.biz.threadpool.*; import cn.hippo4j.config.service.ConfigCacheService; import cn.hippo4j.config.service.biz.ThreadPoolService; -import cn.hippo4j.common.toolkit.BeanUtil; +import cn.hippo4j.config.verify.ConfigModificationVerifyServiceChoose; import cn.hippo4j.console.model.ThreadPoolInstanceInfo; import cn.hippo4j.console.model.WebThreadPoolReqDTO; import cn.hippo4j.console.model.WebThreadPoolRespDTO; @@ -44,13 +40,12 @@ import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; import org.springframework.web.client.RestTemplate; -import java.util.HashMap; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.stream.Collectors; -import static cn.hippo4j.common.constant.Constants.HTTP_EXECUTE_TIMEOUT; import static cn.hippo4j.common.toolkit.ContentUtil.getGroupKey; /** @@ -65,6 +60,8 @@ public class ThreadPoolController { private final BaseInstanceRegistry baseInstanceRegistry; + private final ConfigModificationVerifyServiceChoose configModificationVerifyServiceChoose; + private final RestTemplate restTemplate = new RestTemplate(); @PostMapping("/query/page") @@ -157,6 +154,8 @@ public class ThreadPoolController { continue; } WebThreadPoolRespDTO result = BeanUtil.convert(data, WebThreadPoolRespDTO.class); + result.setItemId(itemId); + result.setTenantId(each.getHolder().getGroupKey().split("[+]")[1]); result.setActive(each.getHolder().getActive()); result.setIdentify(each.getHolder().getIdentify()); result.setClientAddress(each.getHolder().getCallBackUrl()); @@ -191,13 +190,20 @@ public class ThreadPoolController { @PostMapping("/web/update/pool") public Result updateWebThreadPool(@RequestBody WebThreadPoolReqDTO requestParam) { - for (String each : requestParam.getClientAddressList()) { - String urlString = new StringBuilder() - .append("http://") - .append(each) - .append("/web/update/pool") - .toString(); - restTemplate.postForObject(urlString, JSONUtil.toJSONString(requestParam), Object.class); + if (UserContext.getUserRole().equals("ROLE_ADMIN")) { + for (String each : requestParam.getClientAddressList()) { + String urlString = new StringBuilder() + .append("http://") + .append(each) + .append("/web/update/pool") + .toString(); + restTemplate.postForObject(urlString, JSONUtil.toJSONString(requestParam), Object.class); + } + } else { + ConfigModifySaveReqDTO modifySaveReqDTO = BeanUtil.convert(requestParam, ConfigModifySaveReqDTO.class); + modifySaveReqDTO.setModifyUser(UserContext.getUserName()); + modifySaveReqDTO.setType(ConfigModifyTypeConstants.WEB_THREAD_POOL); + configModificationVerifyServiceChoose.choose(modifySaveReqDTO.getType()).saveConfigModifyApplication(modifySaveReqDTO); } return Results.success(); } @@ -215,9 +221,9 @@ public class ThreadPoolController { String groupKey = getGroupKey(tpId, itemTenantKey); Map content = ConfigCacheService.getContent(groupKey); Map activeMap = - leases.stream().map(Lease::getHolder).filter(each -> StringUtil.isNotBlank(each.getActive())) + leases.stream().map(each -> each.getHolder()).filter(each -> StringUtil.isNotBlank(each.getActive())) .collect(Collectors.toMap(InstanceInfo::getIdentify, InstanceInfo::getActive)); - Map clientBasePathMap = leases.stream().map(Lease::getHolder) + Map clientBasePathMap = leases.stream().map(each -> each.getHolder()) .filter(each -> StringUtil.isNotBlank(each.getClientBasePath())) .collect(Collectors.toMap(InstanceInfo::getIdentify, InstanceInfo::getClientBasePath)); List returnThreadPool = new ArrayList<>(); @@ -232,4 +238,5 @@ public class ThreadPoolController { }); return Results.success(returnThreadPool); } + } diff --git a/hippo4j-console/src/main/java/cn/hippo4j/console/model/WebThreadPoolReqDTO.java b/hippo4j-console/src/main/java/cn/hippo4j/console/model/WebThreadPoolReqDTO.java index 9576da15..47deec6a 100644 --- a/hippo4j-console/src/main/java/cn/hippo4j/console/model/WebThreadPoolReqDTO.java +++ b/hippo4j-console/src/main/java/cn/hippo4j/console/model/WebThreadPoolReqDTO.java @@ -27,6 +27,21 @@ import java.util.List; @Data public class WebThreadPoolReqDTO { + /** + * Thread-pool id + */ + private String tenantId; + + /** + * Item id + */ + private String itemId; + + /** + * thread pool instance id + */ + private String identify; + /** * Core pool size */ @@ -42,6 +57,11 @@ public class WebThreadPoolReqDTO { */ private Integer keepAliveTime; + /** + * weather modify all instances + */ + private Boolean modifyAll; + /** * Client address list */ diff --git a/hippo4j-console/src/main/java/cn/hippo4j/console/model/WebThreadPoolRespDTO.java b/hippo4j-console/src/main/java/cn/hippo4j/console/model/WebThreadPoolRespDTO.java index b32cb9d2..73be8520 100644 --- a/hippo4j-console/src/main/java/cn/hippo4j/console/model/WebThreadPoolRespDTO.java +++ b/hippo4j-console/src/main/java/cn/hippo4j/console/model/WebThreadPoolRespDTO.java @@ -25,6 +25,16 @@ import lombok.Data; @Data public class WebThreadPoolRespDTO { + /** + * thread pool tenant id + */ + private String tenantId; + + /** + * item id + */ + private String itemId; + /** * Active */ diff --git a/hippo4j-server/conf/hippo4j_manager.sql b/hippo4j-server/conf/hippo4j_manager.sql index dd21c444..5a3df46f 100644 --- a/hippo4j-server/conf/hippo4j_manager.sql +++ b/hippo4j-server/conf/hippo4j_manager.sql @@ -208,6 +208,29 @@ CREATE TABLE `notify` ( UNIQUE KEY `uk_notify_biz_key` (`tenant_id`,`item_id`,`tp_id`,`platform`,`type`,`del_flag`) USING BTREE ) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 COMMENT='通知表'; +-- ---------------------------- +-- Table structure for his_config_verify +-- ---------------------------- +DROP TABLE IF EXISTS `his_config_verify`; +CREATE TABLE `his_config_verify` ( + `id` bigint UNSIGNED NOT NULL AUTO_INCREMENT, + `type` int NULL DEFAULT NULL COMMENT '变更类型', + `mark` varchar(128) DEFAULT NULL COMMENT '框架线程池类型', + `tenant_id` varchar(128) DEFAULT NULL COMMENT '租户ID', + `item_id` varchar(128) DEFAULT NULL COMMENT '项目ID', + `tp_id` varchar(256) DEFAULT NULL COMMENT '线程池ID', + `identify` varchar(64) DEFAULT NULL COMMENT '线程池唯一标识', + `content` longtext NULL COMMENT '参数变更内容', + `modify_all` tinyint(1) NULL DEFAULT NULL COMMENT '是否全部修改', + `gmt_create` datetime NULL DEFAULT NULL COMMENT '参数变更时间', + `modify_user` varchar(128) DEFAULT NULL COMMENT '修改人', + `verify_status` tinyint(1) NULL DEFAULT NULL COMMENT '审核状态 0:待审核 1:审核通过 2:审核拒绝', + `gmt_verify` datetime NULL DEFAULT NULL COMMENT '审核时间', + `verify_user` varchar(128) DEFAULT NULL COMMENT '审核人', +PRIMARY KEY (`id`) USING BTREE +) ENGINE = InnoDB AUTO_INCREMENT = 1 DEFAULT CHARSET=utf8mb4 COMMENT = '参数变更审核记录表'; + + /* Init SQL */ INSERT IGNORE INTO `tenant` (`id`, `tenant_id`, `tenant_name`, `tenant_desc`, `owner`, `gmt_create`, `gmt_modified`, `del_flag`) VALUES ('1', 'prescription', '处方组', '负责维护处方服务, 包括不限于电子处方等业务', '谢良辰', '2021-10-24 13:42:11', '2021-10-24 13:42:11', '0'); diff --git a/hippo4j-server/conf/sql-upgrade/1.4.2_upgrade.sql b/hippo4j-server/conf/sql-upgrade/1.4.2_upgrade.sql index e0a718b0..1ec3ec5b 100644 --- a/hippo4j-server/conf/sql-upgrade/1.4.2_upgrade.sql +++ b/hippo4j-server/conf/sql-upgrade/1.4.2_upgrade.sql @@ -15,3 +15,23 @@ ALTER TABLE inst_config Modify COLUMN tp_id varchar(256) COMMENT '线程池ID'; ALTER TABLE his_run_data Modify COLUMN tp_id varchar(256) COMMENT '线程池ID'; ALTER TABLE notify Modify COLUMN tp_id varchar(256) COMMENT '线程池ID'; + +DROP TABLE IF EXISTS `his_config_verify`; +CREATE TABLE `his_config_verify` ( + `id` bigint UNSIGNED NOT NULL AUTO_INCREMENT, + `type` int NULL DEFAULT NULL COMMENT '变更类型', + `mark` varchar(128) DEFAULT NULL COMMENT '框架线程池类型', + `tenant_id` varchar(128) DEFAULT NULL COMMENT '租户ID', + `item_id` varchar(128) DEFAULT NULL COMMENT '项目ID', + `tp_id` varchar(256) DEFAULT NULL COMMENT '线程池ID', + `identify` varchar(64) DEFAULT NULL COMMENT '线程池唯一标识', + `content` longtext DEFAULT NULL COMMENT '参数变更内容', + `modify_all` tinyint(1) NULL DEFAULT NULL COMMENT '是否全部修改', + `gmt_create` datetime NULL DEFAULT NULL COMMENT '参数变更时间', + `modify_user` varchar(128) DEFAULT NULL COMMENT '修改人', + `verify_status` tinyint(1) NULL DEFAULT NULL COMMENT '审核状态 0:待审核 1:审核通过 2:审核拒绝', + `gmt_verify` datetime NULL DEFAULT NULL COMMENT '审核时间', + `verify_user` varchar(128) DEFAULT NULL COMMENT '审核人', +PRIMARY KEY (`id`) USING BTREE +) ENGINE = InnoDB AUTO_INCREMENT = 1 DEFAULT CHARSET=utf8mb4 COMMENT = '参数变更审核记录表'; + diff --git a/hippo4j-server/src/main/resources/sql-script/h2/hippo4j_manager.sql b/hippo4j-server/src/main/resources/sql-script/h2/hippo4j_manager.sql index c88c39e8..715fde00 100755 --- a/hippo4j-server/src/main/resources/sql-script/h2/hippo4j_manager.sql +++ b/hippo4j-server/src/main/resources/sql-script/h2/hippo4j_manager.sql @@ -144,6 +144,24 @@ CREATE TABLE IF NOT EXISTS `notify` ( PRIMARY KEY (`id`) ); +CREATE TABLE IF NOT EXISTS `his_config_verify` ( + `id` bigint(20) NOT NULL AUTO_INCREMENT, + `type` int NULL DEFAULT NULL COMMENT '变更类型', + `mark` varchar(128) DEFAULT NULL COMMENT '框架线程池类型', + `tenant_id` varchar(128) DEFAULT NULL COMMENT '租户ID', + `item_id` varchar(128) DEFAULT NULL COMMENT '项目ID', + `tp_id` varchar(256) DEFAULT NULL COMMENT '线程池ID', + `identify` varchar(64) DEFAULT NULL COMMENT '线程池唯一标识', + `content` longtext COMMENT '参数变更内容', + `modify_all` tinyint(1) COMMENT '是否全部修改', + `gmt_create` datetime COMMENT '参数变更时间', + `modify_user` varchar(128) DEFAULT NULL COMMENT '修改人', + `verify_status` tinyint(1) COMMENT '审核状态 0:待审核 1:审核通过 2:审核拒绝', + `gmt_verify` datetime COMMENT '审核时间', + `verify_user` varchar(128) DEFAULT NULL COMMENT '审核人', + PRIMARY KEY (`id`) USING BTREE +); + INSERT INTO `tenant` (`id`, `tenant_id`, `tenant_name`, `tenant_desc`, `owner`, `gmt_create`, `gmt_modified`, `del_flag`) VALUES ('1', 'prescription', '处方组', '负责维护处方服务, 包括不限于电子处方等业务', '谢良辰', '2021-10-24 13:42:11', '2021-10-24 13:42:11', '0'); INSERT INTO `item` (`id`, `tenant_id`, `item_id`, `item_name`, `item_desc`, `owner`, `gmt_create`, `gmt_modified`, `del_flag`) VALUES ('1', 'prescription', 'dynamic-threadpool-example', '动态线程池示例项目', '动态线程池示例项目,对应 Hippo 项目的 example 模块', '马称', '2021-10-24 16:11:00', '2021-10-24 16:11:00', '0'); diff --git a/hippo4j-server/src/main/resources/sql-script/mysql/hippo4j_manager.sql b/hippo4j-server/src/main/resources/sql-script/mysql/hippo4j_manager.sql index 2942b01b..64ed9118 100644 --- a/hippo4j-server/src/main/resources/sql-script/mysql/hippo4j_manager.sql +++ b/hippo4j-server/src/main/resources/sql-script/mysql/hippo4j_manager.sql @@ -198,6 +198,28 @@ CREATE TABLE IF NOT EXISTS `notify` ( UNIQUE KEY `uk_notify_biz_key` (`tenant_id`,`item_id`,`tp_id`,`platform`,`type`,`del_flag`) USING BTREE ) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 COMMENT='通知表'; +-- ---------------------------- +-- Table structure for his_config_verify +-- ---------------------------- +DROP TABLE IF EXISTS `his_config_verify`; +CREATE TABLE `his_config_verify` ( + `id` bigint UNSIGNED NOT NULL AUTO_INCREMENT, + `type` int NULL DEFAULT NULL COMMENT '变更类型', + `mark` varchar(128) DEFAULT NULL COMMENT '框架线程池类型', + `tenant_id` varchar(128) DEFAULT NULL COMMENT '租户ID', + `item_id` varchar(128) DEFAULT NULL COMMENT '项目ID', + `tp_id` varchar(256) DEFAULT NULL COMMENT '线程池ID', + `identify` varchar(64) DEFAULT NULL COMMENT '线程池唯一标识', + `content` longtext NULL COMMENT '参数变更内容', + `modify_all` tinyint(1) NULL DEFAULT NULL COMMENT '是否全部修改', + `gmt_create` datetime NULL DEFAULT NULL COMMENT '参数变更时间', + `modify_user` varchar(128) DEFAULT NULL COMMENT '修改人', + `verify_status` tinyint(1) NULL DEFAULT NULL COMMENT '审核状态 0:待审核 1:审核通过 2:审核拒绝', + `gmt_verify` datetime NULL DEFAULT NULL COMMENT '审核时间', + `verify_user` varchar(128) DEFAULT NULL COMMENT '审核人', + PRIMARY KEY (`id`) USING BTREE +) ENGINE = InnoDB AUTO_INCREMENT = 1 DEFAULT CHARSET=utf8mb4 COMMENT = '参数变更审核记录表'; + /* Init SQL */ INSERT IGNORE INTO `tenant` (`id`, `tenant_id`, `tenant_name`, `tenant_desc`, `owner`, `gmt_create`, `gmt_modified`, `del_flag`) VALUES ('1', 'prescription', '处方组', '负责维护处方服务, 包括不限于电子处方等业务', '谢良辰', '2021-10-24 13:42:11', '2021-10-24 13:42:11', '0'); From 4020c27b7aee6dfc875070e451a4197c4ce3dcb1 Mon Sep 17 00:00:00 2001 From: pirme Date: Sun, 9 Oct 2022 14:32:40 +0800 Subject: [PATCH 4/7] Update the list of contributors --- README.md | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 9ba87985..13f6226b 100644 --- a/README.md +++ b/README.md @@ -157,6 +157,13 @@ Hippo-4J 通过对 JDK 线程池增强,以及扩展三方框架底层线程池 Lijx + + + baymax55 +
+ Baymax55 +
+ liulinfei121 @@ -171,13 +178,6 @@ Hippo-4J 通过对 JDK 线程池增强,以及扩展三方框架底层线程池 Null - - - baymax55 -
- Baymax55 -
- hippo4j From 4666c90bc215aa15b2193f714a1c815009126505 Mon Sep 17 00:00:00 2001 From: shanjianq <49084314+shanjianq@users.noreply.github.com> Date: Sun, 9 Oct 2022 14:56:27 +0800 Subject: [PATCH 5/7] Update developer.md (#778) * Update developer.md * Update developer.md --- docs/docs/community/developer.md | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/docs/docs/community/developer.md b/docs/docs/community/developer.md index 957a051c..b468d82d 100644 --- a/docs/docs/community/developer.md +++ b/docs/docs/community/developer.md @@ -13,9 +13,9 @@ sidebar_position: 2 联系方式 - + 马称 - agentart + itmachen 小马哥的技术专栏 machen@apache.org @@ -54,4 +54,11 @@ sidebar_position: 2 pizihao hao3073liu@163.com + + + 叶炜 + shanjianq + - + 17855368071@163.com + From aec3d98bbf6f3565a6e173df67ea5cb46a172c05 Mon Sep 17 00:00:00 2001 From: pizihao <48643103+pizihao@users.noreply.github.com> Date: Sun, 9 Oct 2022 16:10:28 +0800 Subject: [PATCH 6/7] New feature (#779) * feat : supplement StringUtil * fix : To solve RestTemplate Missing parameter (#775) * fix : again appoint MediaType for request post (#770) --- .../cn/hippo4j/common/toolkit/StringUtil.java | 50 +++++++++++++++++ .../common/toolkit/StringUtilTest.java | 53 ++++++++++++++----- .../service/ThreadPoolAdapterService.java | 41 +++++++------- .../ThreadPoolAdapterController.java | 19 ++++--- .../controller/ThreadPoolController.java | 49 +++++++---------- .../platform/WeChatSendMessageHandler.java | 1 - 6 files changed, 137 insertions(+), 76 deletions(-) diff --git a/hippo4j-common/src/main/java/cn/hippo4j/common/toolkit/StringUtil.java b/hippo4j-common/src/main/java/cn/hippo4j/common/toolkit/StringUtil.java index 553d2acb..e81c1999 100644 --- a/hippo4j-common/src/main/java/cn/hippo4j/common/toolkit/StringUtil.java +++ b/hippo4j-common/src/main/java/cn/hippo4j/common/toolkit/StringUtil.java @@ -223,6 +223,56 @@ public class StringUtil { return sb.toString(); } + /** + * combination CharSequence, get a String + * + * @param charSequences CharSequence, if null or empty, get {@link StringUtil#EMPTY} + * @return String + */ + public static String newBuilder(CharSequence... charSequences) { + if (charSequences == null || charSequences.length == 0) { + return StringUtil.EMPTY; + } + return createBuilder(charSequences).toString(); + } + + /** + * combination CharSequence, get a StringBuilder + * + * @param charSequences CharSequence + * @return StringBuilder + */ + public static StringBuilder createBuilder(CharSequence... charSequences) { + StringBuilder builder = new StringBuilder(); + if (charSequences == null || charSequences.length == 0) { + return builder; + } + for (CharSequence sequence : charSequences) { + builder.append(sequence); + } + return builder; + } + + /** + * combination CharSequence, to StringBuilder + * + * @param builder StringBuilder, if null create a new + * @param charSequences CharSequence + * @return StringBuilder + */ + public static StringBuilder appends(StringBuilder builder, CharSequence... charSequences) { + if (builder == null) { + return createBuilder(charSequences); + } + if (charSequences == null || charSequences.length == 0) { + return builder; + } + for (CharSequence sequence : charSequences) { + builder.append(sequence); + } + return builder; + } + /** * Replace a portion of the string, replacing all found * diff --git a/hippo4j-common/src/test/java/cn/hippo4j/common/toolkit/StringUtilTest.java b/hippo4j-common/src/test/java/cn/hippo4j/common/toolkit/StringUtilTest.java index d2f9173c..9d9c1f02 100644 --- a/hippo4j-common/src/test/java/cn/hippo4j/common/toolkit/StringUtilTest.java +++ b/hippo4j-common/src/test/java/cn/hippo4j/common/toolkit/StringUtilTest.java @@ -18,83 +18,108 @@ package cn.hippo4j.common.toolkit; import org.junit.Test; - -import java.util.Objects; +import org.junit.Assert; public class StringUtilTest { @Test public void assertIsEmpty() { String string = ""; - Assert.isTrue(StringUtil.isEmpty(string)); + Assert.assertTrue(StringUtil.isEmpty(string)); } @Test public void assertIsNotEmpty() { String string = "string"; - Assert.isTrue(StringUtil.isNotEmpty(string)); + Assert.assertTrue(StringUtil.isNotEmpty(string)); } @Test public void emptyToNull() { String string = ""; - Assert.isNull(StringUtil.emptyToNull(string)); + Assert.assertNull(StringUtil.emptyToNull(string)); } @Test public void nullToEmpty() { String string = "null"; - Assert.notEmpty(StringUtil.nullToEmpty(string)); + Assert.assertEquals("null", StringUtil.nullToEmpty(string)); } @Test public void isNullOrEmpty() { String string = "null"; - Assert.isTrue(!StringUtil.isNullOrEmpty(string)); + Assert.assertFalse(StringUtil.isNullOrEmpty(string)); } @Test public void isBlank() { String string = ""; - Assert.isTrue(StringUtil.isBlank(string)); + Assert.assertTrue(StringUtil.isBlank(string)); } @Test public void isNotBlank() { String string = "null"; - Assert.isTrue(StringUtil.isNotBlank(string)); + Assert.assertTrue(StringUtil.isNotBlank(string)); } @Test public void isAllNotEmpty() { String strings = "str"; - Assert.isTrue(StringUtil.isAllNotEmpty(strings)); + Assert.assertTrue(StringUtil.isAllNotEmpty(strings)); } @Test public void hasEmpty() { String strings = ""; - Assert.isTrue(StringUtil.hasEmpty(strings)); + Assert.assertTrue(StringUtil.hasEmpty(strings)); } @Test public void toUnderlineCase() { String string = "str"; String s = StringUtil.toUnderlineCase(string); - Assert.isTrue(Objects.equals(s, "str")); + Assert.assertEquals("str", s); } @Test public void toSymbolCase() { String string = "str"; String s = StringUtil.toSymbolCase(string, StringUtil.UNDERLINE); - Assert.isTrue(Objects.equals(s, "str")); + Assert.assertEquals("str", s); } @Test public void toCamelCase() { String string = "str_str"; String s = StringUtil.toCamelCase(string, StringUtil.UNDERLINE); - Assert.isTrue(Objects.equals(s, "strStr")); + Assert.assertEquals("strStr", s); + } + + @Test + public void newBuilder() { + String s1 = StringUtil.newBuilder(null); + Assert.assertEquals("", s1); + String s2 = StringUtil.newBuilder("H", "ippo", "4j"); + Assert.assertEquals("Hippo4j", s2); + } + + @Test + public void createBuilder() { + StringBuilder s1 = StringUtil.createBuilder(null); + Assert.assertEquals("", s1.toString()); + StringBuilder s2 = StringUtil.createBuilder("H", "ippo", "4j"); + Assert.assertEquals("Hippo4j", s2.toString()); + } + + @Test + public void appends() { + StringBuilder sb1 = StringUtil.appends(null, "H", "ippo", "4j"); + Assert.assertEquals("Hippo4j", sb1.toString()); + StringBuilder sb2 = StringUtil.appends(StringUtil.createBuilder("To "), null); + Assert.assertEquals("To ", sb2.toString()); + StringBuilder sb3 = StringUtil.appends(StringUtil.createBuilder("To "), "H", "ippo", "4j"); + Assert.assertEquals("To Hippo4j", sb3.toString()); } } diff --git a/hippo4j-config/src/main/java/cn/hippo4j/config/service/ThreadPoolAdapterService.java b/hippo4j-config/src/main/java/cn/hippo4j/config/service/ThreadPoolAdapterService.java index d94cc2e6..2a595939 100644 --- a/hippo4j-config/src/main/java/cn/hippo4j/config/service/ThreadPoolAdapterService.java +++ b/hippo4j-config/src/main/java/cn/hippo4j/config/service/ThreadPoolAdapterService.java @@ -30,7 +30,6 @@ import cn.hippo4j.config.model.biz.adapter.ThreadPoolAdapterReqDTO; import cn.hippo4j.config.model.biz.adapter.ThreadPoolAdapterRespDTO; import com.fasterxml.jackson.core.type.TypeReference; import lombok.extern.slf4j.Slf4j; -import org.springframework.http.client.HttpComponentsClientHttpRequestFactory; import org.springframework.stereotype.Service; import org.springframework.web.client.RestTemplate; @@ -38,7 +37,6 @@ import java.util.*; import java.util.concurrent.ConcurrentHashMap; import java.util.stream.Collectors; -import static cn.hippo4j.common.constant.Constants.HTTP_EXECUTE_TIMEOUT; import static cn.hippo4j.common.constant.Constants.IDENTIFY_SLICER_SYMBOL; /** @@ -49,7 +47,7 @@ import static cn.hippo4j.common.constant.Constants.IDENTIFY_SLICER_SYMBOL; public class ThreadPoolAdapterService { /** - * Map>>> + * Map<mark, Map<tenantItem, Map<threadPoolKey, List<ThreadPoolAdapterState>>>> */ private static final Map>>> THREAD_POOL_ADAPTER_MAP = new ConcurrentHashMap<>(); @@ -98,18 +96,23 @@ public class ThreadPoolAdapterService { List addressList = actual.stream().map(ThreadPoolAdapterState::getClientAddress).collect(Collectors.toList()); List result = new ArrayList<>(addressList.size()); addressList.forEach(each -> { - String urlString = new StringBuilder() - .append("http://") - .append(each) - .append("/adapter/thread-pool/info") - .toString(); + StringBuilder builder = StringUtil.createBuilder("http://", each, "/adapter/thread-pool/info"); Map param = new HashMap<>(); param.put("mark", requestParameter.getMark()); param.put("threadPoolKey", requestParameter.getThreadPoolKey()); + List paramKey = new ArrayList<>(param.keySet()); + for (int i = 0; i < paramKey.size(); i++) { + if (i == 0) { + builder.append("?"); + } else { + builder.append("&"); + } + String s = paramKey.get(i); + builder.append(StringUtil.newBuilder(s, "={", s, "}")); + } try { - RestTemplate template = new RestTemplate(); - String resultStr = template.getForObject(urlString, String.class, param); + String resultStr = template.getForObject(builder.toString(), String.class, param); if (StringUtil.isNotBlank(resultStr)) { Result restResult = JSONUtil.parseObject(resultStr, new TypeReference>() { }); @@ -131,22 +134,16 @@ public class ThreadPoolAdapterService { return actual.keySet(); } } - return new HashSet(); + return new HashSet<>(); } public static void remove(String identify) { synchronized (ThreadPoolAdapterService.class) { - THREAD_POOL_ADAPTER_MAP.values().forEach(each -> each.forEach((key, val) -> { - val.forEach((threadPoolKey, states) -> { - Iterator iterator = states.iterator(); - while (iterator.hasNext()) { - ThreadPoolAdapterState adapterState = iterator.next(); - if (Objects.equals(adapterState.getIdentify(), identify)) { - iterator.remove(); - } - } - }); - })); + THREAD_POOL_ADAPTER_MAP.values().forEach(each -> each.forEach((key, val) -> + val.forEach((threadPoolKey, states) -> + states.removeIf(adapterState -> Objects.equals(adapterState.getIdentify(), identify)) + ) + )); } } diff --git a/hippo4j-console/src/main/java/cn/hippo4j/console/controller/ThreadPoolAdapterController.java b/hippo4j-console/src/main/java/cn/hippo4j/console/controller/ThreadPoolAdapterController.java index a30b6d07..30d19620 100644 --- a/hippo4j-console/src/main/java/cn/hippo4j/console/controller/ThreadPoolAdapterController.java +++ b/hippo4j-console/src/main/java/cn/hippo4j/console/controller/ThreadPoolAdapterController.java @@ -21,6 +21,7 @@ import cn.hippo4j.common.constant.ConfigModifyTypeConstants; import cn.hippo4j.common.toolkit.BeanUtil; import cn.hippo4j.common.toolkit.JSONUtil; import cn.hippo4j.common.toolkit.UserContext; +import cn.hippo4j.common.toolkit.StringUtil; import cn.hippo4j.common.web.base.Result; import cn.hippo4j.common.web.base.Results; import cn.hippo4j.config.model.biz.adapter.ThreadPoolAdapterReqDTO; @@ -29,6 +30,9 @@ import cn.hippo4j.config.model.biz.threadpool.ConfigModifySaveReqDTO; import cn.hippo4j.config.service.ThreadPoolAdapterService; import cn.hippo4j.config.verify.ConfigModificationVerifyServiceChoose; import lombok.AllArgsConstructor; +import org.springframework.http.HttpEntity; +import org.springframework.http.HttpHeaders; +import org.springframework.http.MediaType; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; @@ -51,8 +55,6 @@ public class ThreadPoolAdapterController { private final ConfigModificationVerifyServiceChoose configModificationVerifyServiceChoose; - private final RestTemplate restTemplate = new RestTemplate(); - @GetMapping(REGISTER_ADAPTER_BASE_PATH + "/query") public Result> queryAdapterThreadPool(ThreadPoolAdapterReqDTO requestParameter) { List result = threadPoolAdapterService.query(requestParameter); @@ -69,12 +71,13 @@ public class ThreadPoolAdapterController { public Result updateAdapterThreadPool(@RequestBody ThreadPoolAdapterReqDTO requestParameter) { if (UserContext.getUserRole().equals("ROLE_ADMIN")) { for (String each : requestParameter.getClientAddressList()) { - String urlString = new StringBuilder() - .append("http://") - .append(each) - .append("/adapter/thread-pool/update") - .toString(); - restTemplate.postForObject(urlString, JSONUtil.toJSONString(requestParameter), Object.class); + String urlString = StringUtil.newBuilder("http://", each, "/adapter/thread-pool/update"); + RestTemplate restTemplate = new RestTemplate(); + // again appoint MediaType + HttpHeaders requestHeaders = new HttpHeaders(); + requestHeaders.setContentType(MediaType.APPLICATION_JSON); + HttpEntity requestEntity = new HttpEntity<>(JSONUtil.toJSONString(requestParameter), requestHeaders); + restTemplate.postForObject(urlString, requestEntity, Object.class); } } else { ConfigModifySaveReqDTO modifySaveReqDTO = BeanUtil.convert(requestParameter, ConfigModifySaveReqDTO.class); diff --git a/hippo4j-console/src/main/java/cn/hippo4j/console/controller/ThreadPoolController.java b/hippo4j-console/src/main/java/cn/hippo4j/console/controller/ThreadPoolController.java index 09909cf8..1dac5089 100644 --- a/hippo4j-console/src/main/java/cn/hippo4j/console/controller/ThreadPoolController.java +++ b/hippo4j-console/src/main/java/cn/hippo4j/console/controller/ThreadPoolController.java @@ -36,6 +36,9 @@ import cn.hippo4j.discovery.core.BaseInstanceRegistry; import cn.hippo4j.discovery.core.Lease; import com.baomidou.mybatisplus.core.metadata.IPage; import lombok.AllArgsConstructor; +import org.springframework.http.HttpEntity; +import org.springframework.http.HttpHeaders; +import org.springframework.http.MediaType; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; import org.springframework.web.client.RestTemplate; @@ -62,8 +65,6 @@ public class ThreadPoolController { private final ConfigModificationVerifyServiceChoose configModificationVerifyServiceChoose; - private final RestTemplate restTemplate = new RestTemplate(); - @PostMapping("/query/page") public Result> queryNameSpacePage(@RequestBody ThreadPoolQueryReqDTO reqDTO) { return Results.success(threadPoolService.queryThreadPoolPage(reqDTO)); @@ -109,12 +110,8 @@ public class ThreadPoolController { @GetMapping("/run/state/{tpId}") public Result runState(@PathVariable("tpId") String tpId, @RequestParam(value = "clientAddress") String clientAddress) { - String urlString = new StringBuilder() - .append("http://") - .append(clientAddress) - .append("/run/state/") - .append(tpId) - .toString(); + String urlString = StringUtil.newBuilder("http://", clientAddress, "/run/state/", tpId); + RestTemplate restTemplate = new RestTemplate(); String data = restTemplate.getForObject(urlString, String.class, new HashMap<>()); Result result = JSONUtil.parseObject(data, Result.class); return result; @@ -123,12 +120,8 @@ public class ThreadPoolController { @GetMapping("/run/thread/state/{tpId}") public Result runThreadState(@PathVariable("tpId") String tpId, @RequestParam(value = "clientAddress") String clientAddress) { - String urlString = new StringBuilder() - .append("http://") - .append(clientAddress) - .append("/run/thread/state/") - .append(tpId) - .toString(); + String urlString = StringUtil.newBuilder("http://", clientAddress, "/run/thread/state/", tpId); + RestTemplate restTemplate = new RestTemplate(); String data = restTemplate.getForObject(urlString, String.class, new HashMap<>()); Result result = JSONUtil.parseObject(data, Result.class); return result; @@ -166,11 +159,8 @@ public class ThreadPoolController { @GetMapping("/web/base/info") public Result getPoolBaseState(@RequestParam(value = "clientAddress") String clientAddress) { - String urlString = new StringBuilder() - .append("http://") - .append(clientAddress) - .append("/web/base/info") - .toString(); + String urlString = StringUtil.newBuilder("http://", clientAddress, "/web/base/info"); + RestTemplate restTemplate = new RestTemplate(); String data = restTemplate.getForObject(urlString, String.class, new HashMap<>()); Result result = JSONUtil.parseObject(data, Result.class); return result; @@ -178,11 +168,8 @@ public class ThreadPoolController { @GetMapping("/web/run/state") public Result getPoolRunState(@RequestParam(value = "clientAddress") String clientAddress) { - String urlString = new StringBuilder() - .append("http://") - .append(clientAddress) - .append("/web/run/state") - .toString(); + String urlString = StringUtil.newBuilder("http://", clientAddress, "/web/run/state"); + RestTemplate restTemplate = new RestTemplate(); String data = restTemplate.getForObject(urlString, String.class, new HashMap<>()); Result result = JSONUtil.parseObject(data, Result.class); return result; @@ -192,12 +179,13 @@ public class ThreadPoolController { public Result updateWebThreadPool(@RequestBody WebThreadPoolReqDTO requestParam) { if (UserContext.getUserRole().equals("ROLE_ADMIN")) { for (String each : requestParam.getClientAddressList()) { - String urlString = new StringBuilder() - .append("http://") - .append(each) - .append("/web/update/pool") - .toString(); - restTemplate.postForObject(urlString, JSONUtil.toJSONString(requestParam), Object.class); + String urlString = StringUtil.newBuilder("http://", each, "/web/update/pool"); + RestTemplate restTemplate = new RestTemplate(); + // again appoint MediaType + HttpHeaders requestHeaders = new HttpHeaders(); + requestHeaders.setContentType(MediaType.APPLICATION_JSON); + HttpEntity requestEntity = new HttpEntity<>(JSONUtil.toJSONString(requestParam), requestHeaders); + restTemplate.postForObject(urlString, requestEntity, Object.class); } } else { ConfigModifySaveReqDTO modifySaveReqDTO = BeanUtil.convert(requestParam, ConfigModifySaveReqDTO.class); @@ -238,5 +226,4 @@ public class ThreadPoolController { }); return Results.success(returnThreadPool); } - } diff --git a/hippo4j-message/src/main/java/cn/hippo4j/message/platform/WeChatSendMessageHandler.java b/hippo4j-message/src/main/java/cn/hippo4j/message/platform/WeChatSendMessageHandler.java index 38bc9111..65e3b228 100644 --- a/hippo4j-message/src/main/java/cn/hippo4j/message/platform/WeChatSendMessageHandler.java +++ b/hippo4j-message/src/main/java/cn/hippo4j/message/platform/WeChatSendMessageHandler.java @@ -26,7 +26,6 @@ import cn.hippo4j.message.platform.base.RobotMessageExecuteDTO; import lombok.Data; import lombok.experimental.Accessors; import lombok.extern.slf4j.Slf4j; -import org.springframework.http.client.HttpComponentsClientHttpRequestFactory; import org.springframework.web.client.RestTemplate; import static cn.hippo4j.message.platform.constant.WeChatAlarmConstants.*; From 7729ceab69a987200533dfd01ac575864091ed28 Mon Sep 17 00:00:00 2001 From: pirme Date: Sun, 9 Oct 2022 16:10:42 +0800 Subject: [PATCH 7/7] Update the list of contributors --- README.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 13f6226b..55c5b4a0 100644 --- a/README.md +++ b/README.md @@ -101,17 +101,17 @@ Hippo-4J 通过对 JDK 线程池增强,以及扩展三方框架底层线程池 - - BigXin0109 + + shanjianq
- BigXin0109 + Shanjianq
- - shanjianq + + BigXin0109
- Shanjianq + BigXin0109