Delete redundant POM configuration in hippo4j-config POM

pull/327/head
Atmanuclear 3 years ago
parent 9fdf96841f
commit 4715394b91

9
.gitignore vendored

@ -31,3 +31,12 @@ build/
### VS Code ###
.vscode/
# maven plugin ignore
*.gpg
.flattened-pom.xml
### Docs ###
docs/node_modules
docs/build
docs/.docusaurus

@ -1,88 +1,78 @@
![](https://images-machen.oss-cn-beijing.aliyuncs.com/hippo4j-logo-logoly.png)
[👉 《小马哥的代码实战课》官方知识星球来啦!!!](https://xiaomage.info/knowledge-planet/)
![](https://images-machen.oss-cn-beijing.aliyuncs.com/hippo4j-logo-logoly.png)
<p>
<a href="https://github.com/acmenlt/dynamic-threadpool" target="_blank">
<img alt="GitHub" src="https://img.shields.io/github/stars/acmenlt/dynamic-threadpool?label=Stars&style=flat-square&logo=GitHub">
<a href="https://gitee.com/mabaiwancn/hippo4j" target="_blank">
<img alt="Gitee" src="https://gitee.com/mabaiwancn/hippo4j/badge/star.svg?theme=gvp">
</a>
<a href="https://github.com/acmenlt/dynamic-threadpool/blob/develop/LICENSE">
<img src="https://img.shields.io/github/license/acmenlt/dynamic-threadpool?color=42b883&style=flat-square" alt="LICENSE">
<a href="https://github.com/mabaiwan/hippo4j" target="_blank">
<img alt="GitHub" src="https://img.shields.io/github/stars/mabaiwan/hippo4j?label=Stars&style=flat-square&logo=GitHub">
</a>
<a title="Hits" target="_blank" href="https://github.com/acmenlt/dynamic-threadpool">
<a href="https://github.com/mabaiwan/hippo4j/blob/develop/LICENSE">
<img src="https://img.shields.io/github/license/mabaiwan/hippo4j?color=42b883&style=flat-square" alt="LICENSE">
</a>
<a title="Hits" target="_blank" href="https://github.com/mabaiwan/hippo4j">
<img src="https://hits.b3log.org/acmenlt/dynamic-threadpool.svg">
</a>
</p>
## Hippo4J 介绍
Hippo4J 是基于 [美团线程池](https://tech.meituan.com/2020/04/02/java-pooling-pratice-in-meituan.html) 设计理念开发,针对线程池增强动态调参、监控、报警功能
C/S 架构部署使用
部署 Server 端SpringBoot 项目引入 Starter 与之交互
通过 Web 控制台对线程池参数进行动态调整,同时支持集群内线程池的差异化配置
Starter 组件内置线程池参数变更通知,以及运行过载报警功能(支持多通知平台)
## 动态可观测线程池框架
按照租户、项目、线程池的维度划分,配合系统权限,让不同的开发、管理人员负责自己系统的线程池操作
Hippo-4J 通过对 JDK 线程池增强,以及扩展三方框架底层线程池等功能,为业务系统提高线上运行保障能力。
## 解决什么问题
- 全局管控:管理应用线程池实例;
- 动态变更:应用运行时动态变更线程池参数,包括不限于:核心、最大线程数、阻塞队列容量、拒绝策略等;
- 通知报警:内置四种报警通知策略,线程池活跃度、容量水位、拒绝策略以及任务执行时间超长;
- 运行监控:实时查看线程池运行时数据,最近半小时线程池运行数据图表展示;
- 功能扩展:支持线程池任务传递上下文;项目关闭时,支持等待线程池在指定时间内完成任务;
- 多种模式:内置两种使用模式:[依赖配置中心](https://hippo4j.cn/docs/getting-started/hippo4j-core-start) 和 [无中间件依赖](https://hippo4j.cn/docs/getting-started/hippo4j-server-start)
- 容器管理Tomcat、Jetty、Undertow 容器线程池运行时查看和线程数变更;
- 中间件适配Apache RocketMQ、Dubbo、RabbitMQ、Hystrix 消费线程池运行时数据查看和线程数变更。
简单来说Hippo4J 主要为我们解决了下面这些使用原生线程池存在的问题:
- **频繁抛出拒绝策略** :核心线程过小,阻塞队列过小,最大线程过小
- **线程处理速度下降** :核心线程过小,阻塞队列过小,最大线程过大
- **任务堆积** :核心线程过小,阻塞队列过大
- **空闲线程资源浪费** :核心线程或最大线程过大
- **线程池执行不可知** :线程池运行过程中无法得知具体的参数信息,包括不限于任务调度及拒绝策略执行次数
## 模块介绍
- `hippo4j-auth`:用户、角色、权限等
- `hippo4j-common`:多个模块公用代码实现
- `hippo4j-config`:提供线程池准实时参数更新功能
- `hippo4j-console`:对接 Web 前端项目
- `hippo4j-discovery`:提供线程池项目实例注册、续约、下线等功能
- `hippo4j-spring-boot-starter`:负责与 Server 端交互的依赖组件
- `hippo4j-example` :示例工程
- `hippo4j-server` :聚合 Server 端发布需要的模块
- `hippo4j-tools` :操作日志等组件代码
> 看完有所收获的话,右上角帮忙点个 Star谢谢
## 快速开始
[运行 Hippo4J 自带 Demo 参考文档](https://hippox.cn/pages/793dcb/)
对于本地演示目的,请参阅 [Quick start](https://hippo4j.cn/docs/getting-started/hippo4j-server-start)
[在线体验地址](http://console.hippox.cn:6691/index.html) 用户名密码hippo4j / hippo4j
演示环境:
- http://console.hippo4j.cn/index.html
- 用户名/密码hippo4j/hippo4j
## 联系我
对于这个项目,是否有什么不一样看法,同 [作者](https://hippox.cn/pages/dd137d/) 或者创建 [Issues](https://github.com/acmenlt/dynamic-threadpool/issues) 沟通
图片加载不出来,访问 [国内站点](https://hippo4j.cn/docs/other/group)
![image](https://user-images.githubusercontent.com/77398366/169202380-6c068acd-700a-41fa-8823-e01c92bb5e88.png)
## 公众号
## 开发者
如果大家想要实时关注 Hippo4J 最新动态以及干货分享的话,可以关注我的公众号
感谢所有为 Hippo-4J 做出贡献的开发者!
![](https://user-images.githubusercontent.com/77398366/148769916-0ee3a9c2-c8ed-4ce8-849e-038b4a546679.png)
<a href="https://github.com/mabaiwan/hippo4j/graphs/contributors"><img src="https://opencollective.com/hippo4j/contributors.svg?width=890" /></a>
## Stars 趋势
## 我们的荣誉
[![Stargazers over time](https://starchart.cc/acmenlt/dynamic-threadpool.svg)](https://starchart.cc/acmenlt/dynamic-threadpool)
Hippo-4J 获得了一些宝贵的荣誉,这属于每一位对 Hippo-4J 做出过贡献的成员,谢谢各位的付出。
![](https://user-images.githubusercontent.com/77398366/170607238-7308c9be-1d63-46a6-852c-eef2e4cf7405.JPG)
## 鸣谢
## 友情链接
Hippo4J 项目基于或参考以下项目:
- [JavaGuide](https://github.com/Snailclimb/JavaGuide):一份涵盖大部分 Java 程序员所需要掌握的核心知识。
- [Guide-Rpc-Framework](https://github.com/Snailclimb/guide-rpc-framework):一款基于 Netty+Kyro+Zookeeper 实现的自定义 RPC 框架。
- [toBeBetterJavaer](https://github.com/itwanger/toBeBetterJavaer)一份通俗易懂、风趣幽默的Java学习指南内容涵盖Java基础、Java并发编程等核心知识点。
- [Austin](https://github.com/ZhongFuCheng3y/austin):消息推送平台,推送下发【邮件】【短信】【微信服务号】【微信小程序】【企业微信】【钉钉】等消息类型。
- [Nacos](https://github.com/alibaba/nacos)
- [Eureka](https://github.com/Netflix/Eureka)
- [mzt-biz-log](https://github.com/mouzt/mzt-biz-log)
- [equator](https://github.com/dadiyang/equator)
## 鸣谢
Hippo-4J 项目基于或参考以下项目:[Nacos](https://github.com/alibaba/nacos)、[Eureka](https://github.com/Netflix/Eureka)、[Mzt-Biz-Log](https://github.com/mouzt/mzt-biz-log)、[Equator](https://github.com/dadiyang/equator)。
感谢 JetBrains 提供的免费开源 License
<p>
<img src="https://images.gitee.com/uploads/images/2020/0406/220236_f5275c90_5531506.png" alt="图片引用自lets-mica" style="float:left;">
<img src="https://images.gitee.com/uploads/images/2020/0406/220236_f5275c90_5531506.png" alt="图片引用自lets-mica" style="float:left;">
</p>

@ -1,33 +0,0 @@
HELP.md
target/
!.mvn/wrapper/maven-wrapper.jar
!**/src/main/**/target/
!**/src/test/**/target/
### STS ###
.apt_generated
.classpath
.factorypath
.project
.settings
.springBeans
.sts4-cache
### IntelliJ IDEA ###
.idea
*.iws
*.iml
*.ipr
### NetBeans ###
/nbproject/private/
/nbbuild/
/dist/
/nbdist/
/.nb-gradle/
build/
!**/src/main/**/build/
!**/src/test/**/build/
### VS Code ###
.vscode/

@ -2,15 +2,12 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>cn.hippo4j</groupId>
<artifactId>hippo4j-all</artifactId>
<version>${revision}</version>
</parent>
<artifactId>hippo4j-auth</artifactId>
<packaging>jar</packaging>
<properties>
<maven.deploy.skip>true</maven.deploy.skip>
@ -70,5 +67,4 @@
<artifactId>hippo4j-common</artifactId>
</dependency>
</dependencies>
</project>

@ -1,3 +1,20 @@
/*
* 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.auth.config;
import cn.hippo4j.auth.constant.Constants;
@ -26,10 +43,7 @@ import javax.annotation.Resource;
import java.util.stream.Stream;
/**
* .
*
* @author chen.ma
* @date 2021/11/9 21:10
* Global security config.
*/
@Configuration
@EnableWebSecurity
@ -91,5 +105,4 @@ public class GlobalSecurityConfig extends WebSecurityConfigurerAdapter {
String[] ignores = Stream.of("/hippo4j/v1/cs/auth/users/apply/token/**", "/hippo4j/v1/cs/configs/**").toArray(String[]::new);
web.ignoring().antMatchers(ignores);
}
}

@ -1,10 +1,24 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package cn.hippo4j.auth.constant;
/**
* Constants.
*
* @author chen.ma
* @date 2021/11/9 22:24
*/
public class Constants {
@ -13,5 +27,4 @@ public class Constants {
public static final String SPLIT_COMMA = ",";
public static final long TOKEN_VALIDITY_IN_SECONDS = 18000L;
}

@ -1,3 +1,20 @@
/*
* 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.auth.filter;
import cn.hippo4j.auth.model.biz.user.JwtUser;
@ -31,9 +48,6 @@ import static cn.hippo4j.common.constant.Constants.MAP_INITIAL_CAPACITY;
/**
* JWT authentication filter.
*
* @author chen.ma
* @date 2021/11/9 22:21
*/
@Slf4j
public class JWTAuthenticationFilter extends UsernamePasswordAuthenticationFilter {
@ -50,13 +64,12 @@ public class JWTAuthenticationFilter extends UsernamePasswordAuthenticationFilte
@Override
public Authentication attemptAuthentication(HttpServletRequest request,
HttpServletResponse response) throws AuthenticationException {
// 从输入流中获取到登录的信息
// Get logged in information from the input stream.
try {
LoginUser loginUser = new ObjectMapper().readValue(request.getInputStream(), LoginUser.class);
rememberMe.set(loginUser.getRememberMe());
return authenticationManager.authenticate(
new UsernamePasswordAuthenticationToken(loginUser.getUsername(), loginUser.getPassword(), new ArrayList())
);
new UsernamePasswordAuthenticationToken(loginUser.getUsername(), loginUser.getPassword(), new ArrayList()));
} catch (IOException e) {
logger.error("attemptAuthentication error :{}", e);
return null;
@ -71,13 +84,11 @@ public class JWTAuthenticationFilter extends UsernamePasswordAuthenticationFilte
try {
JwtUser jwtUser = (JwtUser) authResult.getPrincipal();
boolean isRemember = rememberMe.get() == 1;
String role = "";
Collection<? extends GrantedAuthority> authorities = jwtUser.getAuthorities();
for (GrantedAuthority authority : authorities) {
role = authority.getAuthority();
}
String token = JwtTokenUtil.createToken(jwtUser.getId(), jwtUser.getUsername(), role, isRemember);
response.setHeader("token", JwtTokenUtil.TOKEN_PREFIX + token);
response.setCharacterEncoding("UTF-8");
@ -95,5 +106,4 @@ public class JWTAuthenticationFilter extends UsernamePasswordAuthenticationFilte
response.setCharacterEncoding("UTF-8");
response.getWriter().write(JSONUtil.toJsonStr(new ReturnT(-1, "Server Error")));
}
}

@ -1,3 +1,20 @@
/*
* 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.auth.filter;
import cn.hippo4j.auth.security.JwtTokenManager;
@ -23,12 +40,10 @@ import java.io.IOException;
import java.util.Collections;
import static cn.hippo4j.common.constant.Constants.ACCESS_TOKEN;
import static cn.hippo4j.common.web.exception.ErrorCodeEnum.LOGIN_TIMEOUT;
/**
* JWT authorization filter.
*
* @author chen.ma
* @date 2021/11/9 22:21
*/
@Slf4j
public class JWTAuthorizationFilter extends BasicAuthenticationFilter {
@ -44,37 +59,38 @@ public class JWTAuthorizationFilter extends BasicAuthenticationFilter {
protected void doFilterInternal(HttpServletRequest request,
HttpServletResponse response,
FilterChain chain) throws IOException, ServletException {
// 验证客户端交互时 Token
// Token when verifying client interaction.
String accessToken = request.getParameter(ACCESS_TOKEN);
if (StrUtil.isNotBlank(accessToken)) {
tokenManager.validateToken(accessToken);
Authentication authentication = this.tokenManager.getAuthentication(accessToken);
SecurityContextHolder.getContext().setAuthentication(authentication);
chain.doFilter(request, response);
return;
}
// 如果请求头中没有 Authorization 信息则直接放行
// If there is no Authorization information in the request header, it will be released directly.
String tokenHeader = request.getHeader(JwtTokenUtil.TOKEN_HEADER);
if (tokenHeader == null || !tokenHeader.startsWith(JwtTokenUtil.TOKEN_PREFIX)) {
chain.doFilter(request, response);
return;
}
// 如果请求头中有 Token, 则进行解析, 并且设置认证信息
// If there is a Token in the request header, it is parsed and the authentication information is set.
try {
SecurityContextHolder.getContext().setAuthentication(getAuthentication(tokenHeader));
} catch (Exception ex) {
// 返回 Json 形式的错误信息
response.setCharacterEncoding("UTF-8");
response.setContentType("application/json; charset=utf-8");
response.getWriter().write(JSONUtil.toJSONString(Results.failure("-1", ex.getMessage())));
String resultStatus = "-1";
if (ex instanceof ServiceException) {
ServiceException serviceException = (ServiceException) ex;
resultStatus = serviceException.errorCode.getCode();
}
response.getWriter().write(JSONUtil.toJSONString(Results.failure(resultStatus, ex.getMessage())));
response.getWriter().flush();
return;
}
try {
super.doFilterInternal(request, response, chain);
} finally {
@ -83,7 +99,7 @@ public class JWTAuthorizationFilter extends BasicAuthenticationFilter {
}
/**
* Token Token.
* Obtain user information from Token and create a new Token.
*
* @param tokenHeader
* @return
@ -92,21 +108,16 @@ public class JWTAuthorizationFilter extends BasicAuthenticationFilter {
String token = tokenHeader.replace(JwtTokenUtil.TOKEN_PREFIX, "");
boolean expiration = JwtTokenUtil.isExpiration(token);
if (expiration) {
throw new ServiceException("登录时间过长,请退出重新登录");
throw new ServiceException(LOGIN_TIMEOUT);
}
String username = JwtTokenUtil.getUsername(token);
String userRole = JwtTokenUtil.getUserRole(token);
UserContext.setUserInfo(username, userRole);
String role = JwtTokenUtil.getUserRole(token);
if (username != null) {
return new UsernamePasswordAuthenticationToken(username, null,
Collections.singleton(new SimpleGrantedAuthority(role))
);
Collections.singleton(new SimpleGrantedAuthority(role)));
}
return null;
}
}

@ -1,3 +1,20 @@
/*
* 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.auth.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
@ -6,9 +23,6 @@ import org.apache.ibatis.annotations.Mapper;
/**
* Permission mapper.
*
* @author chen.ma
* @date 2021/10/30 22:34
*/
@Mapper
public interface PermissionMapper extends BaseMapper<PermissionInfo> {

@ -1,3 +1,20 @@
/*
* 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.auth.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
@ -6,9 +23,6 @@ import org.apache.ibatis.annotations.Mapper;
/**
* Role mapper.
*
* @author chen.ma
* @date 2021/10/30 22:55
*/
@Mapper
public interface RoleMapper extends BaseMapper<RoleInfo> {

@ -1,3 +1,20 @@
/*
* 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.auth.mapper;
import cn.hippo4j.auth.model.UserInfo;
@ -6,9 +23,6 @@ import org.apache.ibatis.annotations.Mapper;
/**
* User mapper.
*
* @author chen.ma
* @date 2021/10/30 21:42
*/
@Mapper
public interface UserMapper extends BaseMapper<UserInfo> {

@ -1,3 +1,20 @@
/*
* 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.auth.model;
import com.baomidou.mybatisplus.annotation.*;
@ -7,9 +24,6 @@ import java.util.Date;
/**
* Permission info.
*
* @author chen.ma
* @date 2021/10/30 22:33
*/
@Data
@TableName("permission")
@ -54,5 +68,4 @@ public class PermissionInfo {
@TableLogic
@TableField(fill = FieldFill.INSERT)
private Integer delFlag;
}

@ -1,3 +1,20 @@
/*
* 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.auth.model;
import com.baomidou.mybatisplus.annotation.*;
@ -7,9 +24,6 @@ import java.util.Date;
/**
* Role info.
*
* @author chen.ma
* @date 2021/10/30 22:54
*/
@Data
@TableName("role")
@ -49,5 +63,4 @@ public class RoleInfo {
@TableLogic
@TableField(fill = FieldFill.INSERT)
private Integer delFlag;
}

@ -1,3 +1,20 @@
/*
* 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.auth.model;
import com.baomidou.mybatisplus.annotation.*;
@ -7,9 +24,6 @@ import java.util.Date;
/**
* User info.
*
* @author chen.ma
* @date 2021/10/30 21:37
*/
@Data
@TableName("user")
@ -54,5 +68,4 @@ public class UserInfo {
@TableLogic
@TableField(fill = FieldFill.INSERT)
private Integer delFlag;
}

@ -1,3 +1,20 @@
/*
* 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.auth.model.biz.permission;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
@ -5,9 +22,6 @@ import lombok.Data;
/**
* Permission query page.
*
* @author chen.ma
* @date 2021/10/30 21:47
*/
@Data
public class PermissionQueryPageReqDTO extends Page {
@ -15,5 +29,4 @@ public class PermissionQueryPageReqDTO extends Page {
public PermissionQueryPageReqDTO(long current, long size) {
super(current, size);
}
}

@ -1,12 +1,26 @@
/*
* 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.auth.model.biz.permission;
import lombok.Data;
/**
* Permission resp dto.
*
* @author chen.ma
* @date 2021/10/30 22:21
*/
@Data
public class PermissionRespDTO {
@ -25,5 +39,4 @@ public class PermissionRespDTO {
* action
*/
private String action;
}

@ -1,3 +1,20 @@
/*
* 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.auth.model.biz.role;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
@ -5,9 +22,6 @@ import lombok.Data;
/**
* Role query page.
*
* @author chen.ma
* @date 2021/10/30 21:47
*/
@Data
public class RoleQueryPageReqDTO extends Page {
@ -15,5 +29,4 @@ public class RoleQueryPageReqDTO extends Page {
public RoleQueryPageReqDTO(long current, long size) {
super(current, size);
}
}

@ -1,24 +1,37 @@
/*
* 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.auth.model.biz.role;
import lombok.Data;
/**
* Role resp dto.
*
* @author chen.ma
* @date 2021/10/30 22:49
*/
@Data
public class RoleRespDTO {
/**
* role
* Role
*/
private String role;
/**
* userName
* User name
*/
private String userName;
}

@ -1,3 +1,20 @@
/*
* 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.auth.model.biz.user;
import lombok.Data;
@ -8,9 +25,6 @@ import java.util.Collection;
/**
* Jwt user.
*
* @author chen.ma
* @date 2021/11/9 22:34
*/
@Data
public class JwtUser implements UserDetails {
@ -54,5 +68,4 @@ public class JwtUser implements UserDetails {
public boolean isEnabled() {
return true;
}
}

@ -1,12 +1,26 @@
/*
* 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.auth.model.biz.user;
import lombok.Data;
/**
* Login user.
*
* @author chen.ma
* @date 2021/11/9 22:41
*/
@Data
public class LoginUser {
@ -25,5 +39,4 @@ public class LoginUser {
* rememberMe
*/
private Integer rememberMe;
}

@ -1,3 +1,20 @@
/*
* 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.auth.model.biz.user;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
@ -6,9 +23,6 @@ import lombok.experimental.Accessors;
/**
* User query page.
*
* @author chen.ma
* @date 2021/10/30 21:47
*/
@Data
@Accessors(chain = true)
@ -18,5 +32,4 @@ public class UserQueryPageReqDTO extends Page {
* userName
*/
private String userName;
}

@ -1,3 +1,20 @@
/*
* 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.auth.model.biz.user;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
@ -6,9 +23,6 @@ import lombok.experimental.Accessors;
/**
* User req dto.
*
* @author chen.ma
* @date 2021/11/11 20:30
*/
@Data
@Accessors(chain = true)
@ -28,5 +42,4 @@ public class UserReqDTO extends Page {
* role
*/
private String role;
}

@ -1,3 +1,20 @@
/*
* 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.auth.model.biz.user;
import com.fasterxml.jackson.annotation.JsonFormat;
@ -7,9 +24,6 @@ import java.util.Date;
/**
* User resp dto.
*
* @author chen.ma
* @date 2021/10/30 21:51
*/
@Data
public class UserRespDTO {
@ -35,5 +49,4 @@ public class UserRespDTO {
*/
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
private Date gmtModified;
}

@ -1,3 +1,20 @@
/*
* 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.auth.security;
import lombok.AllArgsConstructor;
@ -9,10 +26,7 @@ import org.springframework.security.core.AuthenticationException;
import org.springframework.stereotype.Component;
/**
* Auth manager
*
* @author chen.ma
* @date 2021/12/20 20:34
* Auth manager.
*/
@Component
@AllArgsConstructor
@ -39,8 +53,6 @@ public class AuthManager {
} catch (AuthenticationException e) {
throw new AccessException("Unknown user.");
}
return jwtTokenManager.createToken(userName);
}
}

@ -1,3 +1,20 @@
/*
* 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.auth.security;
import cn.hutool.core.util.StrUtil;
@ -20,19 +37,14 @@ import static cn.hippo4j.common.constant.Constants.AUTHORITIES_KEY;
/**
* Jwt token manager.
*
* @author chen.ma
* @date 2021/12/20 20:36
*/
@Component
public class JwtTokenManager {
public String createToken(String userName) {
long now = System.currentTimeMillis();
Date validity;
validity = new Date(now + TOKEN_VALIDITY_IN_SECONDS * 1000L);
Claims claims = Jwts.claims().setSubject(userName);
return Jwts.builder().setClaims(claims).setExpiration(validity)
.signWith(SignatureAlgorithm.HS512, SECRET).compact();
@ -50,12 +62,9 @@ public class JwtTokenManager {
*/
public Authentication getAuthentication(String token) {
Claims claims = Jwts.parser().setSigningKey(SECRET).parseClaimsJws(token).getBody();
List<GrantedAuthority> authorities = AuthorityUtils
.commaSeparatedStringToAuthorityList((String) claims.get(AUTHORITIES_KEY));
User principal = new User(claims.getSubject(), StrUtil.EMPTY, authorities);
return new UsernamePasswordAuthenticationToken(principal, StrUtil.EMPTY, authorities);
}
}

@ -1,3 +1,20 @@
/*
* 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.auth.service;
import cn.hippo4j.auth.model.biz.permission.PermissionRespDTO;
@ -5,14 +22,11 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
/**
* Permission service.
*
* @author chen.ma
* @date 2021/10/30 22:13
*/
public interface PermissionService {
/**
* .
* Paging query permission list.
*
* @param pageNo
* @param pageSize
@ -21,7 +35,7 @@ public interface PermissionService {
IPage<PermissionRespDTO> listPermission(int pageNo, int pageSize);
/**
* .
* Add permission.
*
* @param role
* @param resource
@ -30,12 +44,11 @@ public interface PermissionService {
void addPermission(String role, String resource, String action);
/**
* .
* Remove permission.
*
* @param role
* @param resource
* @param action
*/
void deletePermission(String role, String resource, String action);
}

@ -1,3 +1,20 @@
/*
* 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.auth.service;
import com.baomidou.mybatisplus.core.metadata.IPage;
@ -7,14 +24,11 @@ import java.util.List;
/**
* Role service.
*
* @author chen.ma
* @date 2021/10/30 22:45
*/
public interface RoleService {
/**
* .
* Paging query role list.
*
* @param pageNo
* @param pageSize
@ -23,7 +37,7 @@ public interface RoleService {
IPage<RoleRespDTO> listRole(int pageNo, int pageSize);
/**
* .
* Add role.
*
* @param role
* @param userName
@ -31,7 +45,7 @@ public interface RoleService {
void addRole(String role, String userName);
/**
* .
* Delete role.
*
* @param role
* @param userName
@ -39,11 +53,10 @@ public interface RoleService {
void deleteRole(String role, String userName);
/**
* .
* Fuzzy search by role.
*
* @param role
* @return
*/
List<String> getRoleLike(String role);
}

@ -1,3 +1,20 @@
/*
* 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.auth.service;
import cn.hippo4j.auth.model.biz.user.UserQueryPageReqDTO;
@ -9,14 +26,11 @@ import java.util.List;
/**
* User service.
*
* @author chen.ma
* @date 2021/10/30 21:34
*/
public interface UserService {
/**
* .
* Paging query user list.
*
* @param reqDTO
* @return
@ -24,28 +38,28 @@ public interface UserService {
IPage<UserRespDTO> listUser(UserQueryPageReqDTO reqDTO);
/**
* .
* New users.
*
* @param reqDTO
*/
void addUser(UserReqDTO reqDTO);
/**
* .
* Modify user.
*
* @param reqDTO
*/
void updateUser(UserReqDTO reqDTO);
/**
* .
* Delete users.
*
* @param userName
*/
void deleteUser(String userName);
/**
* .
* Fuzzy search by username.
*
* @param userName
* @return
@ -53,11 +67,10 @@ public interface UserService {
List<String> getUserLikeUsername(String userName);
/**
* .
* Get user details.
*
* @param reqDTO
* @return
*/
UserRespDTO getUser(UserReqDTO reqDTO);
}

@ -1,3 +1,20 @@
/*
* 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.auth.service.impl;
import cn.hippo4j.auth.mapper.PermissionMapper;
@ -16,9 +33,6 @@ import org.springframework.stereotype.Service;
/**
* Permission service impl.
*
* @author chen.ma
* @date 2021/10/30 22:32
*/
@Service
@AllArgsConstructor
@ -44,7 +58,6 @@ public class PermissionServiceImpl implements PermissionService {
if (existPermissionInfo != null) {
throw new RuntimeException("权限重复");
}
PermissionInfo insertPermission = new PermissionInfo();
insertPermission.setRole(role);
insertPermission.setResource(resource);
@ -58,8 +71,6 @@ public class PermissionServiceImpl implements PermissionService {
.eq(StrUtil.isNotBlank(role), PermissionInfo::getRole, role)
.eq(StrUtil.isNotBlank(resource), PermissionInfo::getResource, resource)
.eq(StrUtil.isNotBlank(action), PermissionInfo::getAction, action);
permissionMapper.delete(updateWrapper);
}
}

@ -1,3 +1,20 @@
/*
* 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.auth.service.impl;
import cn.hippo4j.auth.mapper.RoleMapper;
@ -21,9 +38,6 @@ import java.util.stream.Collectors;
/**
* Role service impl.
*
* @author chen.ma
* @date 2021/10/30 22:53
*/
@Service
@AllArgsConstructor
@ -37,7 +51,6 @@ public class RoleServiceImpl implements RoleService {
public IPage<RoleRespDTO> listRole(int pageNo, int pageSize) {
RoleQueryPageReqDTO queryPage = new RoleQueryPageReqDTO(pageNo, pageSize);
IPage<RoleInfo> selectPage = roleMapper.selectPage(queryPage, null);
return selectPage.convert(each -> BeanUtil.toBean(each, RoleRespDTO.class));
}
@ -49,7 +62,6 @@ public class RoleServiceImpl implements RoleService {
if (roleInfo != null) {
throw new RuntimeException("角色名重复");
}
RoleInfo insertRole = new RoleInfo();
insertRole.setRole(role);
insertRole.setUserName(userName);
@ -63,12 +75,10 @@ public class RoleServiceImpl implements RoleService {
LambdaQueryWrapper<RoleInfo> queryWrapper = Wrappers.lambdaQuery(RoleInfo.class).eq(RoleInfo::getUserName, userName);
roleStrList = roleMapper.selectList(queryWrapper).stream().map(RoleInfo::getRole).collect(Collectors.toList());
}
LambdaUpdateWrapper<RoleInfo> updateWrapper = Wrappers.lambdaUpdate(RoleInfo.class)
.eq(StrUtil.isNotBlank(role), RoleInfo::getRole, role)
.eq(StrUtil.isNotBlank(userName), RoleInfo::getUserName, userName);
roleMapper.delete(updateWrapper);
roleStrList.forEach(each -> permissionService.deletePermission(each, "", ""));
}
@ -77,11 +87,8 @@ public class RoleServiceImpl implements RoleService {
LambdaQueryWrapper<RoleInfo> queryWrapper = Wrappers.lambdaQuery(RoleInfo.class)
.like(RoleInfo::getRole, role)
.select(RoleInfo::getRole);
List<RoleInfo> roleInfos = roleMapper.selectList(queryWrapper);
List<String> roleNames = roleInfos.stream().map(RoleInfo::getRole).collect(Collectors.toList());
return roleNames;
}
}

@ -1,3 +1,20 @@
/*
* 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.auth.service.impl;
import cn.hippo4j.auth.mapper.UserMapper;
@ -15,9 +32,6 @@ import java.util.Set;
/**
* User details service impl.
*
* @author chen.ma
* @date 2021/11/9 22:26
*/
public class UserDetailsServiceImpl implements UserDetailsService {
@ -27,16 +41,12 @@ public class UserDetailsServiceImpl implements UserDetailsService {
@Override
public UserDetails loadUserByUsername(String userName) throws UsernameNotFoundException {
UserInfo userInfo = userMapper.selectOne(Wrappers.lambdaQuery(UserInfo.class).eq(UserInfo::getUserName, userName));
JwtUser jwtUser = new JwtUser();
jwtUser.setId(userInfo.getId());
jwtUser.setUsername(userName);
jwtUser.setPassword(userInfo.getPassword());
Set<SimpleGrantedAuthority> authorities = Collections.singleton(new SimpleGrantedAuthority(userInfo.getRole() + ""));
jwtUser.setAuthorities(authorities);
return jwtUser;
}
}

@ -1,3 +1,20 @@
/*
* 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.auth.service.impl;
import cn.hippo4j.auth.mapper.UserMapper;
@ -26,9 +43,6 @@ import java.util.stream.Collectors;
/**
* User service impl.
*
* @author chen.ma
* @date 2021/10/30 21:40
*/
@Service
@AllArgsConstructor
@ -45,7 +59,6 @@ public class UserServiceImpl implements UserService {
LambdaQueryWrapper<UserInfo> queryWrapper = Wrappers.lambdaQuery(UserInfo.class)
.eq(StringUtil.isNotBlank(reqDTO.getUserName()), UserInfo::getUserName, reqDTO.getUserName());
IPage<UserInfo> selectPage = userMapper.selectPage(reqDTO, queryWrapper);
return selectPage.convert(each -> BeanUtil.toBean(each, UserRespDTO.class));
}
@ -57,7 +70,6 @@ public class UserServiceImpl implements UserService {
if (existUserInfo != null) {
throw new RuntimeException("用户名重复");
}
reqDTO.setPassword(bCryptPasswordEncoder.encode(reqDTO.getPassword()));
UserInfo insertUser = BeanUtil.toBean(reqDTO, UserInfo.class);
userMapper.insert(insertUser);
@ -69,7 +81,6 @@ public class UserServiceImpl implements UserService {
reqDTO.setPassword(bCryptPasswordEncoder.encode(reqDTO.getPassword()));
}
UserInfo updateUser = BeanUtil.toBean(reqDTO, UserInfo.class);
LambdaUpdateWrapper<UserInfo> updateWrapper = Wrappers.lambdaUpdate(UserInfo.class)
.eq(UserInfo::getUserName, reqDTO.getUserName());
userMapper.update(updateUser, updateWrapper);
@ -80,7 +91,6 @@ public class UserServiceImpl implements UserService {
LambdaUpdateWrapper<UserInfo> updateWrapper = Wrappers.lambdaUpdate(UserInfo.class)
.eq(UserInfo::getUserName, userName);
userMapper.delete(updateWrapper);
// roleService.deleteRole("", userName);
}
@Override
@ -88,10 +98,8 @@ public class UserServiceImpl implements UserService {
LambdaQueryWrapper<UserInfo> queryWrapper = Wrappers.lambdaQuery(UserInfo.class)
.like(UserInfo::getUserName, userName)
.select(UserInfo::getUserName);
List<UserInfo> userInfos = userMapper.selectList(queryWrapper);
List<String> userNames = userInfos.stream().map(UserInfo::getUserName).collect(Collectors.toList());
return userNames;
}
@ -99,11 +107,9 @@ public class UserServiceImpl implements UserService {
public UserRespDTO getUser(UserReqDTO reqDTO) {
Wrapper queryWrapper = Wrappers.lambdaQuery(UserInfo.class).eq(UserInfo::getUserName, reqDTO.getUserName());
UserInfo userInfo = userMapper.selectOne(queryWrapper);
UserRespDTO respUser = Optional.ofNullable(userInfo)
.map(each -> BeanUtil.toBean(each, UserRespDTO.class))
.orElseThrow(() -> new ServiceException("查询无此用户, 可以尝试清空缓存或退出登录."));
return respUser;
}
}

@ -1,3 +1,20 @@
/*
* 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.auth.toolkit;
import cn.hippo4j.auth.constant.Constants;
@ -14,10 +31,7 @@ import java.util.List;
import static cn.hippo4j.common.constant.Constants.MAP_INITIAL_CAPACITY;
/**
* Jwt token util.
*
* @author chen.ma
* @date 2021/11/9 22:43
* JWT token util.
*/
public class JwtTokenUtil {
@ -28,22 +42,22 @@ public class JwtTokenUtil {
public static final String ISS = "admin";
/**
* Key
* Character key.
*/
private static final String ROLE_CLAIMS = "rol";
/**
* 3600 , 24
* Expiration time is 3600 seconds, which is 24 hours.
*/
private static final long EXPIRATION = 86400L;
/**
* 7
* 7 days after selecting Remember me.
*/
private static final long EXPIRATION_REMEMBER = 7 * EXPIRATION;
/**
* Token.
* Create Token.
*
* @param id
* @param username
@ -66,7 +80,7 @@ public class JwtTokenUtil {
}
/**
* Token .
* Get the username from Token.
*
* @param token
* @return
@ -77,7 +91,7 @@ public class JwtTokenUtil {
}
/**
* Token .
* Get the username from Token.
*
* @param token
* @return
@ -88,7 +102,7 @@ public class JwtTokenUtil {
}
/**
* .
* Get user role.
*
* @param token
* @return
@ -98,7 +112,7 @@ public class JwtTokenUtil {
}
/**
* .
* Has it expired.
*
* @param token
* @return
@ -114,5 +128,4 @@ public class JwtTokenUtil {
private static Claims getTokenBody(String token) {
return Jwts.parser().setSigningKey(SECRET).parseClaimsJws(token).getBody();
}
}

@ -1,3 +1,20 @@
/*
* 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.auth.toolkit;
import lombok.Data;
@ -7,9 +24,6 @@ import java.io.Serializable;
/**
* ReturnT.
*
* @author chen.ma
* @date 2021/11/10 00:00
*/
@Data
@NoArgsConstructor
@ -36,5 +50,4 @@ public class ReturnT<T> implements Serializable {
this.code = SUCCESS_CODE;
this.content = content;
}
}

@ -1,33 +0,0 @@
HELP.md
target/
!.mvn/wrapper/maven-wrapper.jar
!**/src/main/**/target/
!**/src/test/**/target/
### STS ###
.apt_generated
.classpath
.factorypath
.project
.settings
.springBeans
.sts4-cache
### IntelliJ IDEA ###
.idea
*.iws
*.iml
*.ipr
### NetBeans ###
/nbproject/private/
/nbbuild/
/dist/
/nbdist/
/.nb-gradle/
build/
!**/src/main/**/build/
!**/src/test/**/build/
### VS Code ###
.vscode/

@ -2,18 +2,12 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>cn.hippo4j</groupId>
<artifactId>hippo4j-all</artifactId>
<version>${revision}</version>
</parent>
<artifactId>hippo4j-common</artifactId>
<packaging>jar</packaging>
<name>${project.artifactId}</name>
<description>${project.artifactId}</description>
<dependencies>
<dependency>
@ -44,14 +38,20 @@
<dependency>
<groupId>com.aliyun</groupId>
<artifactId>alibaba-dingtalk-service-sdk</artifactId>
<optional>true</optional>
<!-- 用户反馈其中 javax.jms 无法下载, 未发现 log4j 用处, 暂且排除 -->
<exclusions>
<exclusion>
<artifactId>log4j</artifactId>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
</exclusion>
</exclusions>
<optional>true</optional>
</dependency>
<dependency>
<groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId>
<version>1.14</version>
</dependency>
</dependencies>
@ -86,5 +86,4 @@
</plugin>
</plugins>
</build>
</project>

@ -1,3 +1,20 @@
/*
* 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.api;
import lombok.Data;
@ -5,9 +22,6 @@ import lombok.experimental.Accessors;
/**
* Client close hook execute.
*
* @author chen.ma
* @date 2022/1/6 22:14
*/
public interface ClientCloseHookExecute {
@ -36,7 +50,5 @@ public interface ClientCloseHookExecute {
* groupKey
*/
private String groupKey;
}
}

@ -1,12 +1,26 @@
/*
* 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.api;
import java.util.List;
/**
* Json facade.
*
* @author chen.ma
* @date 2021/12/13 20:01
*/
public interface JsonFacade {
@ -37,5 +51,4 @@ public interface JsonFacade {
* @return
*/
<T> List<T> parseArray(String text, Class<T> clazz);
}

@ -1,3 +1,20 @@
/*
* 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.api;
import cn.hippo4j.common.notify.NotifyConfigDTO;
@ -7,9 +24,6 @@ import java.util.Map;
/**
* Notify config builder.
*
* @author chen.ma
* @date 2022/2/24 19:50
*/
public interface NotifyConfigBuilder {
@ -19,5 +33,4 @@ public interface NotifyConfigBuilder {
* @return
*/
Map<String, List<NotifyConfigDTO>> buildNotify();
}

@ -1,3 +1,20 @@
/*
* 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.api;
import cn.hippo4j.common.model.ThreadDetailStateInfo;
@ -7,9 +24,6 @@ import java.util.concurrent.ThreadPoolExecutor;
/**
* Get thread status in thread pool.
*
* @author chen.ma
* @date 2022/1/9 12:47
*/
public interface ThreadDetailState {
@ -28,5 +42,4 @@ public interface ThreadDetailState {
* @return
*/
List<ThreadDetailStateInfo> getThreadDetailStateInfo(ThreadPoolExecutor threadPoolExecutor);
}

@ -1,10 +1,26 @@
/*
* 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.api;
import java.util.Map;
/**
* Thread pool dynamic refresh.
*
* @author chen.ma
* @date 2022/2/26 12:26
* Thread-pool dynamic refresh.
*/
public interface ThreadPoolDynamicRefresh {
@ -15,4 +31,12 @@ public interface ThreadPoolDynamicRefresh {
*/
void dynamicRefresh(String content);
/**
* Dynamic refresh.
*
* @param content
* @param newValueChangeMap
*/
default void dynamicRefresh(String content, Map<String, Object> newValueChangeMap) {
}
}

@ -1,3 +1,20 @@
/*
* 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.config;
import org.springframework.beans.BeansException;
@ -9,9 +26,6 @@ import java.util.Map;
/**
* Application context holder.
*
* @author chen.ma
* @date 2021/6/20 18:49
*/
public class ApplicationContextHolder implements ApplicationContextAware {
@ -76,5 +90,4 @@ public class ApplicationContextHolder implements ApplicationContextAware {
public static ApplicationContext getInstance() {
return CONTEXT;
}
}

@ -1,10 +1,24 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package cn.hippo4j.common.constant;
/**
* Constants.
*
* @author chen.ma
* @date 2021/6/16 23:01
*/
public class Constants {
@ -50,6 +64,10 @@ public class Constants {
public static final String MONITOR_PATH = BASE_PATH + "/monitor";
public static final String REGISTER_ADAPTER_BASE_PATH = BASE_PATH + "/adapter/thread-pool";
public static final String REGISTER_ADAPTER_PATH = REGISTER_ADAPTER_BASE_PATH + "/register";
public static final String HEALTH_CHECK_PATH = BASE_PATH + "/health/check";
public static final String PROBE_MODIFY_REQUEST = "Listening-Configs";
@ -82,4 +100,7 @@ public class Constants {
public static final String UNKNOWN = "unknown";
public static final String EXECUTE_TIMEOUT_TRACE = "executeTimeoutTrace";
public static final int HTTP_EXECUTE_TIMEOUT = 5000;
}

@ -1,20 +1,28 @@
/*
* 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.design.builder;
import java.io.Serializable;
/**
* Builder pattern interface definition.
*
* @author chen.ma
* @date 2021/7/5 21:39
*/
public interface Builder<T> extends Serializable {
/**
* Build.
*
* @return
*/
T build();
}

@ -1,3 +1,20 @@
/*
* 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.design.observer;
import cn.hippo4j.common.toolkit.CollectionUtil;
@ -11,9 +28,6 @@ import java.util.concurrent.ConcurrentHashMap;
/**
* Send observer notification.
*
* @author chen.ma
* @date 2021/12/25 19:47
*/
@Slf4j
public class AbstractSubjectCenter {
@ -128,7 +142,5 @@ public class AbstractSubjectCenter {
* Clear config cache.
*/
CLEAR_CONFIG_CACHE
}
}

@ -1,10 +1,24 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package cn.hippo4j.common.design.observer;
/**
* Observer.
*
* @author chen.ma
* @date 2021/12/25 19:46
*/
public interface Observer<T> {
@ -14,5 +28,4 @@ public interface Observer<T> {
* @param observerMessage
*/
void accept(ObserverMessage<T> observerMessage);
}

@ -1,18 +1,26 @@
/*
* 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.design.observer;
/**
* Message notifying observer.
*
* @author chen.ma
* @date 2021/12/25 19:54
*/
public interface ObserverMessage<T> {
/**
* Message.
*
* @return
*/
T message();
}

@ -1,10 +1,24 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package cn.hippo4j.common.enums;
/**
* Del enum.
*
* @author chen.ma
* @date 2021/3/26 18:45
*/
public enum DelEnum {
@ -36,5 +50,4 @@ public enum DelEnum {
public String toString() {
return statusCode;
}
}

@ -1,12 +1,26 @@
/*
* 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;
import java.util.Objects;
/**
* Enable enum.
*
* @author chen.ma
* @date 2021/12/21 20:34
*/
public enum EnableEnum {
@ -42,5 +56,4 @@ public enum EnableEnum {
public static boolean getBool(Integer intStatusCode) {
return Objects.equals(intStatusCode, EnableEnum.YES.getIntCode()) ? true : false;
}
}

@ -1,3 +1,20 @@
/*
* 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.executor;
import java.util.concurrent.Executors;
@ -6,9 +23,6 @@ import java.util.concurrent.ThreadFactory;
/**
* Executor factory.
*
* @author chen.ma
* @date 2021/6/23 18:35
*/
public class ExecutorFactory {
@ -24,5 +38,4 @@ public class ExecutorFactory {
return executorService;
}
}
}

@ -1,3 +1,20 @@
/*
* 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.executor;
import java.util.HashMap;
@ -9,10 +26,7 @@ import java.util.concurrent.ExecutorService;
import java.util.concurrent.atomic.AtomicBoolean;
/**
* Thread Pool Manager.
*
* @author chen.ma
* @date 2021/6/23 18:36
* Thread-pool manager.
*/
public class ThreadPoolManager {
@ -42,7 +56,6 @@ public class ThreadPoolManager {
lockers.put(tenantId, new Object());
}
}
final Object monitor = lockers.get(tenantId);
synchronized (monitor) {
Map<String, Set<ExecutorService>> map = resourcesManager.get(tenantId);
@ -59,5 +72,4 @@ public class ThreadPoolManager {
map.get(group).add(executor);
}
}
}

@ -1,20 +1,27 @@
/*
* 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.function;
/**
* Matcher.
*
* @author chen.ma
* @date 2022/1/9 13:29
*/
@FunctionalInterface
public interface Matcher<T> {
/**
* Match.
*
* @param t
* @return
*/
boolean match(T t);
}

@ -1,17 +1,27 @@
/*
* 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.function;
/**
* .
*
* @author chen.ma
* @date 2021/11/9 00:06
* No args consumer.
*/
@FunctionalInterface
public interface NoArgsConsumer {
/**
*
*/
void accept();
}

@ -1,3 +1,20 @@
/*
* 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.model;
import lombok.Getter;
@ -7,9 +24,6 @@ import java.io.Serializable;
/**
* Global remote pool info.
*
* @author chen.ma
* @date 2021/6/23 21:08
*/
@Getter
@Setter
@ -81,5 +95,4 @@ public class GlobalRemotePoolInfo implements Serializable {
* content
*/
private String content;
}

@ -1,3 +1,20 @@
/*
* 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.model;
import lombok.Data;
@ -8,9 +25,6 @@ import lombok.extern.slf4j.Slf4j;
/**
* Instance info.
*
* @author chen.ma
* @date 2021/7/13 22:10
*/
@Slf4j
@Getter
@ -167,8 +181,5 @@ public class InstanceInfo {
private String lastDirtyTimestamp;
private String status;
}
}

@ -1,29 +0,0 @@
package cn.hippo4j.common.model;
import lombok.Data;
/**
* Many pool run state info.
*
* @author chen.ma
* @date 2022/1/8 12:54
*/
@Data
public class ManyPoolRunStateInfo extends PoolRunStateInfo {
/**
* identify
*/
private String identify;
/**
* active
*/
private String active;
/**
* state
*/
private String state;
}

@ -1,46 +0,0 @@
package cn.hippo4j.common.model;
import lombok.Data;
import lombok.experimental.Accessors;
/**
* Pool base info.
*
* @author chen.ma
* @date 2022/1/22 12:10
*/
@Data
@Accessors(chain = true)
public class PoolBaseInfo {
/**
* coreSize
*/
private Integer coreSize;
/**
* maximumSize
*/
private Integer maximumSize;
/**
* queueType
*/
private String queueType;
/**
* queueCapacity
*/
private Integer queueCapacity;
/**
* rejectedName
*/
private String rejectedName;
/**
* keepAliveTime
*/
private Long keepAliveTime;
}

@ -1,102 +0,0 @@
package cn.hippo4j.common.model;
/**
* Pool parameter.
*
* @author chen.ma
* @date 2021/6/24 16:04
*/
public interface PoolParameter {
/**
* tenantId
*
* @return
*/
String getTenantId();
/**
* itemId
*
* @return
*/
String getItemId();
/**
* tpId
*
* @return
*/
String getTpId();
/**
* coreSize
*
* @return
*/
Integer getCoreSize();
/**
* maxSize
*
* @return
*/
Integer getMaxSize();
/**
* queueType
*
* @return
*/
Integer getQueueType();
/**
* capacity
*
* @return
*/
Integer getCapacity();
/**
* keepAliveTime
*
* @return
*/
Integer getKeepAliveTime();
/**
* rejectedType
*
* @return
*/
Integer getRejectedType();
/**
* isAlarm
*
* @return
*/
Integer getIsAlarm();
/**
* capacityAlarm
*
* @return
*/
Integer getCapacityAlarm();
/**
* livenessAlarm
*
* @return
*/
Integer getLivenessAlarm();
/**
* allowCoreThreadTimeOut
*
* @return
*/
Integer getAllowCoreThreadTimeOut();
}

@ -1,90 +0,0 @@
package cn.hippo4j.common.model;
import lombok.Data;
import lombok.experimental.Accessors;
import java.io.Serializable;
/**
* Thread pool parameter info.
*
* @author chen.ma
* @date 2021/6/16 23:18
*/
@Data
@Accessors(chain = true)
public class PoolParameterInfo implements PoolParameter, Serializable {
private static final long serialVersionUID = -7123935122108553864L;
/**
* tenantId
*/
private String tenantId;
/**
* itemId
*/
private String itemId;
/**
* tpId
*/
private String tpId;
/**
* content
*/
private String content;
/**
* coreSize
*/
private Integer coreSize;
/**
* maxSize
*/
private Integer maxSize;
/**
* queueType
*/
private Integer queueType;
/**
* capacity
*/
private Integer capacity;
/**
* keepAliveTime
*/
private Integer keepAliveTime;
/**
* rejectedType
*/
private Integer rejectedType;
/**
* isAlarm
*/
private Integer isAlarm;
/**
* capacityAlarm
*/
private Integer capacityAlarm;
/**
* livenessAlarm
*/
private Integer livenessAlarm;
/**
* allowCoreThreadTimeOut
*/
private Integer allowCoreThreadTimeOut;
}

@ -1,98 +0,0 @@
package cn.hippo4j.common.model;
import lombok.Getter;
import lombok.Setter;
import java.io.Serializable;
/**
* Pool run state info.
*
* @author chen.ma
* @date 2021/7/7 18:57
*/
@Getter
@Setter
public class PoolRunStateInfo extends PoolBaseInfo implements Serializable {
/**
* currentLoad
*/
private String currentLoad;
/**
* peakLoad
*/
private String peakLoad;
/**
* tpId
*/
private String tpId;
/**
* activeCount
*/
private Integer activeCount;
/**
* poolSize
*/
private Integer poolSize;
/**
* activeSize
*/
private Integer activeSize;
/**
* The maximum number of threads that enter the thread pool at the same time
*/
private Integer largestPoolSize;
/**
* queueSize
*/
private Integer queueSize;
/**
* queueRemainingCapacity
*/
private Integer queueRemainingCapacity;
/**
* completedTaskCount
*/
private Long completedTaskCount;
/**
* rejectCount
*/
private Long rejectCount;
/**
* host
*/
private String host;
/**
* memoryProportion
*/
private String memoryProportion;
/**
* freeMemory
*/
private String freeMemory;
/**
* clientLastRefreshTime
*/
private String clientLastRefreshTime;
/**
* timestamp
*/
private Long timestamp;
}

@ -1,3 +1,20 @@
/*
* 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.model;
import lombok.Data;
@ -7,9 +24,6 @@ import java.util.List;
/**
* Thread detail state info.
*
* @author chen.ma
* @date 2022/1/9 12:36
*/
@Data
@Accessors(chain = true)
@ -34,5 +48,4 @@ public class ThreadDetailStateInfo {
* threadStack
*/
private List<String> threadStack;
}

@ -1,3 +1,20 @@
/*
* 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.model;
import lombok.AllArgsConstructor;
@ -6,9 +23,6 @@ import lombok.NoArgsConstructor;
/**
* Token info.
*
* @author chen.ma
* @date 2021/12/20 20:02
*/
@Data
@NoArgsConstructor
@ -24,5 +38,4 @@ public class TokenInfo {
* tokenTtl
*/
private Long tokenTtl;
}

@ -1,3 +1,20 @@
/*
* 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.monitor;
import lombok.Data;
@ -7,9 +24,6 @@ import java.util.List;
/**
* Base message.
*
* @author chen.ma
* @date 2021/12/7 20:31
*/
@Data
@NoArgsConstructor
@ -29,5 +43,4 @@ public abstract class AbstractMessage<T extends Message> implements Message {
* message
*/
private List<T> messages;
}

@ -1,3 +1,20 @@
/*
* 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.monitor;
import java.io.Serializable;
@ -5,9 +22,6 @@ import java.util.List;
/**
* Abstract message monitoring interface.
*
* @author chen.ma
* @date 2021/12/6 20:16
*/
public interface Message<T extends Message> extends Serializable {
@ -31,5 +45,4 @@ public interface Message<T extends Message> extends Serializable {
* @return
*/
List<T> getMessages();
}

@ -1,3 +1,20 @@
/*
* 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.monitor;
import java.util.List;
@ -5,9 +22,6 @@ import java.util.Map;
/**
* Message request.
*
* @author chen.ma
* @date 2021/12/10 21:17
*/
public interface MessageRequest<T extends Message> {
@ -31,5 +45,4 @@ public interface MessageRequest<T extends Message> {
* @return
*/
MessageTypeEnum getMessageType();
}

@ -1,10 +1,24 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package cn.hippo4j.common.monitor;
/**
* Message type enum.
*
* @author chen.ma
* @date 2021/12/7 19:34
*/
public enum MessageTypeEnum {
@ -17,5 +31,4 @@ public enum MessageTypeEnum {
* DEFAULT
*/
DEFAULT
}

@ -1,22 +1,37 @@
/*
* 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.monitor;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.io.Serializable;
import java.util.List;
import java.util.Map;
/**
* Message wrapper.
*
* @author chen.ma
* @date 2021/12/7 22:42
*/
@Data
@NoArgsConstructor
@AllArgsConstructor
public class MessageWrapper implements MessageRequest<Message> {
public class MessageWrapper implements MessageRequest<Message>, Serializable {
/**
* contentParams
@ -47,5 +62,4 @@ public class MessageWrapper implements MessageRequest<Message> {
public MessageTypeEnum getMessageType() {
return messageType;
}
}

@ -1,3 +1,20 @@
/*
* 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.monitor;
import lombok.Data;
@ -5,9 +22,6 @@ import lombok.NoArgsConstructor;
/**
* Dynamic thread pool runtime data.
*
* @author chen.ma
* @date 2021/12/6 18:18
*/
@Data
@NoArgsConstructor
@ -67,5 +81,4 @@ public class RuntimeMessage extends AbstractMessage {
* timestamp
*/
private Long timestamp;
}

@ -1,3 +1,20 @@
/*
* 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.notify;
import cn.hutool.core.util.StrUtil;
@ -5,10 +22,7 @@ import lombok.Builder;
import lombok.Data;
/**
* .
*
* @author chen.ma
* @date 2021/10/28 22:15
* Alarm control dto.
*/
@Data
@Builder
@ -37,5 +51,4 @@ public class AlarmControlDTO {
public String buildPk() {
return StrUtil.builder(threadPool, "+", platform).toString();
}
}

@ -1,3 +1,20 @@
/*
* 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.notify;
import cn.hippo4j.common.constant.Constants;
@ -13,9 +30,6 @@ import java.util.concurrent.locks.ReentrantLock;
/**
* Alarm control assembly.
*
* @author chen.ma
* @date 2021/10/28 21:24
*/
public class AlarmControlHandler {
@ -35,7 +49,6 @@ public class AlarmControlHandler {
if (cache == null) {
return false;
}
String pkId = cache.getIfPresent(alarmControl.getTypeEnum().name());
if (StrUtil.isBlank(pkId)) {
ReentrantLock lock = threadPoolLock.get(threadPoolKey);
@ -51,7 +64,6 @@ public class AlarmControlHandler {
lock.unlock();
}
}
return false;
}
@ -68,10 +80,8 @@ public class AlarmControlHandler {
.expireAfterWrite(interval, TimeUnit.MINUTES)
.build();
threadPoolAlarmCache.put(threadPoolKey, cache);
// Set the lock to prevent false sending of alarm information.
ReentrantLock reentrantLock = new ReentrantLock();
threadPoolLock.put(threadPoolKey, reentrantLock);
}
}

@ -1,114 +0,0 @@
package cn.hippo4j.common.notify;
import cn.hippo4j.common.api.NotifyConfigBuilder;
import cn.hippo4j.common.config.ApplicationContextHolder;
import cn.hippo4j.common.notify.request.AlarmNotifyRequest;
import cn.hippo4j.common.notify.request.ChangeParameterNotifyRequest;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.StrUtil;
import com.google.common.collect.Maps;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.CommandLineRunner;
import java.util.List;
import java.util.Map;
/**
* Base send message service impl.
*
* @author chen.ma
* @date 2022/2/22 21:32
*/
@Slf4j
@RequiredArgsConstructor
public class BaseSendMessageServiceImpl implements HippoSendMessageService, CommandLineRunner {
private final NotifyConfigBuilder notifyConfigBuilder;
private final AlarmControlHandler alarmControlHandler;
private final Map<String, List<NotifyConfigDTO>> notifyConfigs = Maps.newHashMap();
private final Map<String, SendMessageHandler> sendMessageHandlers = Maps.newHashMap();
@Override
public void sendAlarmMessage(NotifyTypeEnum typeEnum, AlarmNotifyRequest alarmNotifyRequest) {
String threadPoolId = alarmNotifyRequest.getThreadPoolId();
String buildKey = StrUtil.builder(threadPoolId, "+", "ALARM").toString();
List<NotifyConfigDTO> notifyList = notifyConfigs.get(buildKey);
if (CollUtil.isEmpty(notifyList)) {
log.warn("Please configure alarm notification on the server. key :: [{}]", threadPoolId);
return;
}
notifyList.forEach(each -> {
try {
SendMessageHandler messageHandler = sendMessageHandlers.get(each.getPlatform());
if (messageHandler == null) {
log.warn("Please configure alarm notification on the server. key :: [{}]", threadPoolId);
return;
}
if (isSendAlarm(each.getThreadPoolId(), each.setTypeEnum(typeEnum))) {
messageHandler.sendAlarmMessage(each, alarmNotifyRequest);
}
} catch (Exception ex) {
log.warn("Failed to send thread pool alarm notification. key :: [{}]", threadPoolId, ex);
}
});
}
@Override
public void sendChangeMessage(ChangeParameterNotifyRequest changeParameterNotifyRequest) {
String threadPoolId = changeParameterNotifyRequest.getThreadPoolId();
String buildKey = StrUtil.builder(threadPoolId, "+", "CONFIG").toString();
List<NotifyConfigDTO> notifyList = notifyConfigs.get(buildKey);
if (CollUtil.isEmpty(notifyList)) {
log.warn("Please configure alarm notification on the server. key :: [{}]", threadPoolId);
return;
}
notifyList.forEach(each -> {
try {
SendMessageHandler messageHandler = sendMessageHandlers.get(each.getPlatform());
if (messageHandler == null) {
log.warn("Please configure alarm notification on the server. key :: [{}]", threadPoolId);
return;
}
messageHandler.sendChangeMessage(each, changeParameterNotifyRequest);
} catch (Exception ex) {
log.warn("Failed to send thread pool change notification. key :: [{}]", threadPoolId, ex);
}
});
}
/**
* Is send alarm.
*
* @param threadPoolId
* @param notifyInfo
* @return
*/
private boolean isSendAlarm(String threadPoolId, NotifyConfigDTO notifyInfo) {
AlarmControlDTO alarmControl = AlarmControlDTO.builder()
.threadPool(threadPoolId)
.platform(notifyInfo.getPlatform())
.typeEnum(notifyInfo.getTypeEnum())
.build();
return alarmControlHandler.isSendAlarm(alarmControl);
}
@Override
public void run(String... args) throws Exception {
Map<String, SendMessageHandler> sendMessageHandlerMap =
ApplicationContextHolder.getBeansOfType(SendMessageHandler.class);
sendMessageHandlerMap.values().forEach(each -> sendMessageHandlers.put(each.getType(), each));
Map<String, List<NotifyConfigDTO>> buildNotify = notifyConfigBuilder.buildNotify();
notifyConfigs.putAll(buildNotify);
}
}

@ -1,13 +1,27 @@
/*
* 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.notify;
import cn.hippo4j.common.notify.request.AlarmNotifyRequest;
import cn.hippo4j.common.notify.request.ChangeParameterNotifyRequest;
/**
* Send message service.
*
* @author chen.ma
* @date 2022/2/22 19:56
* Hippo4j send message service.
*/
public interface HippoSendMessageService {
@ -25,5 +39,4 @@ public interface HippoSendMessageService {
* @param changeParameterNotifyRequest
*/
void sendChangeMessage(ChangeParameterNotifyRequest changeParameterNotifyRequest);
}

@ -1,13 +1,27 @@
/*
* 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.notify;
import lombok.Data;
import lombok.experimental.Accessors;
/**
* .
*
* @author chen.ma
* @date 2021/11/17 22:12
* Notify config dto.
*/
@Data
@Accessors(chain = true)
@ -26,7 +40,7 @@ public class NotifyConfigDTO {
/**
* 线id
*/
private String threadPoolId;
private String tpId;
/**
*
@ -43,6 +57,11 @@ public class NotifyConfigDTO {
*/
private String secretKey;
/**
*
*/
private String secret;
/**
*
*/
@ -57,5 +76,4 @@ public class NotifyConfigDTO {
*
*/
private NotifyTypeEnum typeEnum;
}

@ -1,10 +1,24 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package cn.hippo4j.common.notify;
/**
* Notify platform enum.
*
* @author chen.ma
* @date 2021/8/15 15:50
*/
public enum NotifyPlatformEnum {
@ -22,5 +36,4 @@ public enum NotifyPlatformEnum {
* WECHAT
*/
WECHAT
}

@ -1,10 +1,24 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package cn.hippo4j.common.notify;
/**
* Notify type enum.
*
* @author chen.ma
* @date 2022/2/22 19:44
*/
public enum NotifyTypeEnum {
@ -26,6 +40,10 @@ public enum NotifyTypeEnum {
/**
* REJECT
*/
REJECT
REJECT,
/**
* TIMEOUT
*/
TIMEOUT
}

@ -1,12 +1,26 @@
/*
* 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.notify;
import cn.hippo4j.common.notify.request.base.NotifyRequest;
/**
* Send message handler.
*
* @author chen.ma
* @date 2021/8/15 15:44
*/
public interface SendMessageHandler<T extends NotifyRequest, R extends NotifyRequest> {
@ -32,5 +46,4 @@ public interface SendMessageHandler<T extends NotifyRequest, R extends NotifyReq
* @param changeParameterNotifyRequest
*/
void sendChangeMessage(NotifyConfigDTO notifyConfig, R changeParameterNotifyRequest);
}

@ -1,3 +1,20 @@
/*
* 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.notify;
import lombok.Data;
@ -9,9 +26,6 @@ import java.util.Map;
/**
* Thread pool notify alarm.
*
* @author chen.ma
* @date 2021/8/15 19:13
*/
@Data
@NoArgsConstructor
@ -41,9 +55,15 @@ public class ThreadPoolNotifyAlarm {
*/
private Integer interval;
/**
* receive
*/
private String receive;
/**
* receives
* ps
*/
@Deprecated
private Map<String, String> receives;
}

@ -1,3 +1,20 @@
/*
* 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.notify;
import lombok.Data;
@ -6,9 +23,6 @@ import java.util.List;
/**
* Thread pool notify DTO.
*
* @author chen.ma
* @date 2022/2/24 19:08
*/
@Data
public class ThreadPoolNotifyDTO {
@ -22,5 +36,4 @@ public class ThreadPoolNotifyDTO {
* notifyList
*/
private List<NotifyConfigDTO> notifyList;
}

@ -1,10 +1,24 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package cn.hippo4j.common.notify.platform;
/**
* Ding alarm constants.
*
* @author chen.ma
* @date 2021/11/26 20:03
*/
public class DingAlarmConstants {
@ -23,33 +37,48 @@ public class DingAlarmConstants {
*/
public static final String DING_NOTICE_TITLE = "动态线程池通知";
/**
* Trace
*/
public static final String DING_ALARM_TIMOUT_TRACE_REPLACE_TXT = "<font color=#708090 size=2>链路信息:%s</font> \n\n";
/**
*
*/
public static final String DING_ALARM_TIMOUT_REPLACE_TXT =
"<font color=#708090 size=2>任务执行时间:%d / ms </font> \n\n" +
"<font color=#708090 size=2>超时时间:%d / ms</font> \n\n" +
DING_ALARM_TIMOUT_TRACE_REPLACE_TXT +
" --- \n\n ";
/**
* 线
*/
public static final String DING_ALARM_TXT =
"<font color='#FF0000'>[警报] </font>%s - 动态线程池运行告警 \n\n" +
"**<font color=#FF0000>[警报] </font>%s - 动态线程池运行告警%s** \n\n" +
" --- \n\n " +
"<font color='#708090' size=2>线程池ID%s</font> \n\n " +
"<font color='#708090' size=2>应用名称:%s</font> \n\n " +
"<font color='#778899' size=2>应用实例:%s</font> \n\n " +
"<font color='#778899' size=2>报警类型:%s</font> \n\n " +
"<font color=#708090 size=2>线程池ID%s</font> \n\n " +
"<font color=#708090 size=2>应用名称:%s</font> \n\n " +
"<font color=#778899 size=2>应用实例:%s</font> \n\n " +
"<font color=#778899 size=2>实例标识%s</font> \n\n " +
" --- \n\n " +
"<font color='#708090' size=2>核心线程数:%d</font> \n\n " +
"<font color='#708090' size=2>最大线程数:%d</font> \n\n " +
"<font color='#708090' size=2>当前线程数:%d</font> \n\n " +
"<font color='#708090' size=2>活跃线程数:%d</font> \n\n " +
"<font color='#708090' size=2>最大任务数:%d</font> \n\n " +
"<font color='#708090' size=2>线程池任务总量:%d</font> \n\n " +
"<font color=#708090 size=2>核心线程数:%d</font> \n\n " +
"<font color=#708090 size=2>最大线程数:%d</font> \n\n " +
"<font color=#708090 size=2>当前线程数:%d</font> \n\n " +
"<font color=#708090 size=2>活跃线程数:%d</font> \n\n " +
"<font color=#708090 size=2>同存最大线程数:%d</font> \n\n " +
"<font color=#708090 size=2>线程池任务总量:%d</font> \n\n " +
" --- \n\n " +
"<font color='#708090' size=2>队列类型:%s</font> \n\n " +
"<font color='#708090' size=2>队列容量:%d</font> \n\n " +
"<font color='#708090' size=2>队列元素个数:%d</font> \n\n " +
"<font color='#708090' size=2>队列剩余个数:%d</font> \n\n " +
"<font color=#708090 size=2>队列类型:%s</font> \n\n " +
"<font color=#708090 size=2>队列容量:%d</font> \n\n " +
"<font color=#708090 size=2>队列元素个数:%d</font> \n\n " +
"<font color=#708090 size=2>队列剩余个数:%d</font> \n\n " +
" --- \n\n " +
"<font color='#708090' size=2>拒绝策略:%s</font> \n\n" +
"<font color='#708090' size=2>拒绝策略执行次数:</font><font color='#FF0000' size=2>%d</font> \n\n " +
"<font color='#708090' size=2>OWNER@%s</font> \n\n" +
"<font color='#708090' size=2>提示:%d 分钟内此线程池不会重复告警(可配置)</font> \n\n" +
DING_ALARM_TIMOUT_REPLACE_TXT +
"<font color=#708090 size=2>拒绝策略:%s</font> \n\n" +
"<font color=#708090 size=2>拒绝策略执行次数:</font><font color=#FF0000 size=2>%d</font> \n\n " +
"<font color=#708090 size=2>OWNER@%s</font> \n\n" +
"<font color=#708090 size=2>提示:%d 分钟内此线程池不会重复告警(可配置)</font> \n\n" +
" --- \n\n " +
"**播报时间:%s**";
@ -57,26 +86,25 @@ public class DingAlarmConstants {
* 线
*/
public static final String DING_NOTICE_TXT =
"<font color='#2a9d8f'>[通知] </font>%s - 动态线程池参数变更 \n\n" +
"**<font color=#2a9d8f>[通知] </font>%s - 动态线程池参数变更** \n\n" +
" --- \n\n " +
"<font color='#708090' size=2>线程池ID%s</font> \n\n " +
"<font color='#708090' size=2>应用名称:%s</font> \n\n " +
"<font color='#778899' size=2>应用实例:%s</font> \n\n " +
" --- \n\n " +
"<font color='#708090' size=2>核心线程数:%s</font> \n\n " +
"<font color='#708090' size=2>最大线程数:%s</font> \n\n " +
"<font color='#708090' size=2>核心线程超时:%s</font> \n\n " +
"<font color='#708090' size=2>线程存活时间:%s / SECONDS</font> \n\n" +
"<font color=#708090 size=2>线程池ID%s</font> \n\n " +
"<font color=#708090 size=2>应用名称:%s</font> \n\n " +
"<font color=#778899 size=2>应用实例:%s</font> \n\n " +
" --- \n\n " +
"<font color='#708090' size=2>队列类型:%s</font> \n\n " +
"<font color='#708090' size=2>队列容量:%s</font> \n\n " +
"<font color=#708090 size=2>核心线程数:%s</font> \n\n " +
"<font color=#708090 size=2>最大线程数:%s</font> \n\n " +
"<font color=#708090 size=2>核心线程超时:%s</font> \n\n " +
"<font color=#708090 size=2>线程存活时间:%s</font> \n\n" +
"<font color=#708090 size=2>执行超时时间:%s</font> \n\n" +
" --- \n\n " +
"<font color='#708090' size=2>AGO 拒绝策略:%s</font> \n\n" +
"<font color='#708090' size=2>NOW 拒绝策略:%s</font> \n\n" +
"<font color=#708090 size=2>队列类型:%s</font> \n\n " +
"<font color=#708090 size=2>队列容量:%s</font> \n\n " +
"<font color=#708090 size=2>AGO 拒绝策略:%s</font> \n\n" +
"<font color=#708090 size=2>NOW 拒绝策略:%s</font> \n\n" +
" --- \n\n " +
"<font color='#708090' size=2>提示:动态线程池配置变更实时通知(无限制)</font> \n\n" +
"<font color='#708090' size=2>OWNER@%s</font> \n\n" +
"<font color=#708090 size=2>提示:动态线程池配置变更实时通知(无限制)</font> \n\n" +
"<font color=#708090 size=2>OWNER@%s</font> \n\n" +
" --- \n\n " +
"**播报时间:%s**";
}

@ -1,11 +1,31 @@
/*
* 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.notify.platform;
import cn.hippo4j.common.notify.NotifyConfigDTO;
import cn.hippo4j.common.notify.NotifyPlatformEnum;
import cn.hippo4j.common.notify.NotifyTypeEnum;
import cn.hippo4j.common.notify.SendMessageHandler;
import cn.hippo4j.common.notify.request.AlarmNotifyRequest;
import cn.hippo4j.common.notify.request.ChangeParameterNotifyRequest;
import cn.hippo4j.common.toolkit.StringUtil;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.StrUtil;
import com.dingtalk.api.DefaultDingTalkClient;
import com.dingtalk.api.DingTalkClient;
import com.dingtalk.api.request.OapiRobotSendRequest;
@ -13,17 +33,19 @@ import com.google.common.base.Joiner;
import com.google.common.collect.Lists;
import com.taobao.api.ApiException;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.codec.binary.Base64;
import javax.crypto.Mac;
import javax.crypto.spec.SecretKeySpec;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import java.util.List;
import java.util.Objects;
import static cn.hippo4j.common.notify.platform.DingAlarmConstants.DING_ALARM_TXT;
import static cn.hippo4j.common.notify.platform.DingAlarmConstants.DING_NOTICE_TXT;
import static cn.hippo4j.common.notify.platform.DingAlarmConstants.*;
/**
* Send ding notification message.
*
* @author chen.ma
* @date 2021/8/15 15:49
*/
@Slf4j
public class DingSendMessageHandler implements SendMessageHandler<AlarmNotifyRequest, ChangeParameterNotifyRequest> {
@ -37,19 +59,37 @@ public class DingSendMessageHandler implements SendMessageHandler<AlarmNotifyReq
public void sendAlarmMessage(NotifyConfigDTO notifyConfig, AlarmNotifyRequest alarmNotifyRequest) {
String[] receives = notifyConfig.getReceives().split(",");
String afterReceives = Joiner.on(", @").join(receives);
String dingAlarmTxt;
String dingAlarmTimoutReplaceTxt;
if (Objects.equals(alarmNotifyRequest.getNotifyTypeEnum(), NotifyTypeEnum.TIMEOUT)) {
String executeTimeoutTrace = alarmNotifyRequest.getExecuteTimeoutTrace();
if (StringUtil.isNotBlank(executeTimeoutTrace)) {
String dingAlarmTimoutTraceReplaceTxt = String.format(DING_ALARM_TIMOUT_TRACE_REPLACE_TXT, executeTimeoutTrace);
dingAlarmTimoutReplaceTxt = StrUtil.replace(DING_ALARM_TIMOUT_REPLACE_TXT, DING_ALARM_TIMOUT_TRACE_REPLACE_TXT, dingAlarmTimoutTraceReplaceTxt);
} else {
dingAlarmTimoutReplaceTxt = StrUtil.replace(DING_ALARM_TIMOUT_REPLACE_TXT, DING_ALARM_TIMOUT_TRACE_REPLACE_TXT, "");
}
dingAlarmTimoutReplaceTxt = String.format(dingAlarmTimoutReplaceTxt, alarmNotifyRequest.getExecuteTime(), alarmNotifyRequest.getExecuteTimeOut());
dingAlarmTxt = StrUtil.replace(DING_ALARM_TXT, DING_ALARM_TIMOUT_REPLACE_TXT, dingAlarmTimoutReplaceTxt);
} else {
dingAlarmTxt = StrUtil.replace(DING_ALARM_TXT, DING_ALARM_TIMOUT_REPLACE_TXT, "");
}
String[] strings = alarmNotifyRequest.getIdentify().split("_");
String text = String.format(
DING_ALARM_TXT,
dingAlarmTxt,
// 环境
alarmNotifyRequest.getActive(),
// 报警类型
alarmNotifyRequest.getNotifyTypeEnum(),
// 线程池ID
alarmNotifyRequest.getThreadPoolId(),
// 应用名称
alarmNotifyRequest.getAppName(),
// 实例信息
alarmNotifyRequest.getIdentify(),
// 报警类型
notifyConfig.getTypeEnum(),
// Host
strings[0],
// 实例ID
strings[1],
// 核心线程数
alarmNotifyRequest.getCorePoolSize(),
// 最大线程数
@ -79,22 +119,15 @@ public class DingSendMessageHandler implements SendMessageHandler<AlarmNotifyReq
// 报警频率
notifyConfig.getInterval(),
// 当前时间
DateUtil.now()
);
execute(notifyConfig.getSecretKey(), DingAlarmConstants.DING_ALARM_TITLE, text, Lists.newArrayList(receives));
DateUtil.now());
execute(notifyConfig, DingAlarmConstants.DING_ALARM_TITLE, text, Lists.newArrayList(receives));
}
@Override
public void sendChangeMessage(NotifyConfigDTO notifyConfig, ChangeParameterNotifyRequest changeParameterNotifyRequest) {
String threadPoolId = changeParameterNotifyRequest.getThreadPoolId();
String[] receives = notifyConfig.getReceives().split(",");
String afterReceives = Joiner.on(", @").join(receives);
/**
* hesitant e.g.
*/
String text = String.format(
DING_NOTICE_TXT,
// 环境
@ -113,6 +146,8 @@ public class DingSendMessageHandler implements SendMessageHandler<AlarmNotifyReq
changeParameterNotifyRequest.getBeforeAllowsCoreThreadTimeOut() + " ➲ " + changeParameterNotifyRequest.getNowAllowsCoreThreadTimeOut(),
// 线程存活时间
changeParameterNotifyRequest.getBeforeKeepAliveTime() + " ➲ " + changeParameterNotifyRequest.getNowKeepAliveTime(),
// 执行超时时间
changeParameterNotifyRequest.getBeforeExecuteTimeOut() + " ➲ " + changeParameterNotifyRequest.getNowExecuteTimeOut(),
// 阻塞队列
changeParameterNotifyRequest.getBlockingQueueName(),
// 阻塞队列容量
@ -123,33 +158,41 @@ public class DingSendMessageHandler implements SendMessageHandler<AlarmNotifyReq
// 告警手机号
afterReceives,
// 当前时间
DateUtil.now()
);
DateUtil.now());
execute(notifyConfig.getSecretKey(), DingAlarmConstants.DING_NOTICE_TITLE, text, Lists.newArrayList(receives));
execute(notifyConfig, DingAlarmConstants.DING_NOTICE_TITLE, text, Lists.newArrayList(receives));
}
private void execute(String secretKey, String title, String text, List<String> mobiles) {
String serverUrl = DingAlarmConstants.DING_ROBOT_SERVER_URL + secretKey;
private void execute(NotifyConfigDTO notifyConfig, String title, String text, List<String> mobiles) {
String serverUrl = DingAlarmConstants.DING_ROBOT_SERVER_URL + notifyConfig.getSecretKey();
String secret = notifyConfig.getSecret();
if (StringUtil.isNotBlank(secret)) {
long timestamp = System.currentTimeMillis();
String stringToSign = timestamp + "\n" + secret;
try {
Mac mac = Mac.getInstance("HmacSHA256");
mac.init(new SecretKeySpec(secret.getBytes(StandardCharsets.UTF_8), "HmacSHA256"));
byte[] signData = mac.doFinal(stringToSign.getBytes(StandardCharsets.UTF_8));
String sign = URLEncoder.encode(new String(Base64.encodeBase64(signData)), StandardCharsets.UTF_8.name());
serverUrl = serverUrl + "&timestamp=" + timestamp + "&sign=" + sign;
} catch (Exception ex) {
log.error("Failed to sign the message sent by nailing.", ex);
}
}
DingTalkClient dingTalkClient = new DefaultDingTalkClient(serverUrl);
OapiRobotSendRequest request = new OapiRobotSendRequest();
request.setMsgtype("markdown");
OapiRobotSendRequest.Markdown markdown = new OapiRobotSendRequest.Markdown();
markdown.setTitle(title);
markdown.setText(text);
OapiRobotSendRequest.At at = new OapiRobotSendRequest.At();
at.setAtMobiles(mobiles);
request.setAt(at);
request.setMarkdown(markdown);
try {
dingTalkClient.execute(request);
} catch (ApiException ex) {
log.error("Ding failed to send message", ex);
}
}
}

@ -1,10 +1,24 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package cn.hippo4j.common.notify.platform;
/**
* lark alarm constants.
*
* @author imyzt
* @date 2021-11-23 19:29
* Lark alarm constants.
*/
public class LarkAlarmConstants {
@ -30,14 +44,30 @@ public class LarkAlarmConstants {
*/
public static final String LARK_OPENID_PREFIX = "ou_";
/**
* Trace
*/
public static final String LARK_ALARM_TIMOUT_TRACE_REPLACE_TXT = ",{\"is_short\":true,\"text\":{\"content\":\"** 链路信息:** %s\",\"tag\":\"lark_md\"}}";
/**
*
*/
public static final String LARK_ALARM_TIMOUT_REPLACE_TXT =
"{\"fields\":[{\"is_short\":true,\"text\":{\"content\":\"** 任务执行时间:** %s\",\"tag\":\"lark_md\"}},{\"is_short\":true,\"text\":{\"content\":\"** 超时时间:** %s\",\"tag\":\"lark_md\"}}" +
LARK_ALARM_TIMOUT_TRACE_REPLACE_TXT +
"],\"tag\":\"div\"},{\"tag\":\"hr\"},";
/**
* lark alarm json str
*/
public static final String LARK_ALARM_JSON_STR = "{\"msg_type\":\"interactive\",\"card\":{\"config\":{\"wide_screen_mode\":true},\"header\":{\"template\":\"red\",\"title\":{\"content\":\"[\uD83D\uDD25警报] %s 动态线程池运行告警\",\"tag\":\"plain_text\"}},\"elements\":[{\"fields\":[{\"is_short\":true,\"text\":{\"content\":\"** 线程池ID** %s\",\"tag\":\"lark_md\"}},{\"is_short\":true,\"text\":{\"content\":\"** 应用名称:** %s\",\"tag\":\"lark_md\"}},{\"is_short\":true,\"text\":{\"content\":\"** 应用实例:** %s\",\"tag\":\"lark_md\"}},{\"is_short\":true,\"text\":{\"content\":\"** 报警类型:** %s\",\"tag\":\"lark_md\"}}],\"tag\":\"div\"},{\"tag\":\"hr\"},{\"fields\":[{\"is_short\":true,\"text\":{\"content\":\"** 核心线程数:** %s\",\"tag\":\"lark_md\"}},{\"is_short\":true,\"text\":{\"content\":\"** 最大线程数:** %s\",\"tag\":\"lark_md\"}},{\"is_short\":true,\"text\":{\"content\":\"** 当前线程数:** %s\",\"tag\":\"lark_md\"}},{\"is_short\":true,\"text\":{\"content\":\"** 活跃线程数:** %s\",\"tag\":\"lark_md\"}},{\"is_short\":true,\"text\":{\"content\":\"** 最大任务数:** %s\",\"tag\":\"lark_md\"}},{\"is_short\":true,\"text\":{\"content\":\"** 线程池任务总量:** %s\",\"tag\":\"lark_md\"}}],\"tag\":\"div\"},{\"tag\":\"hr\"},{\"fields\":[{\"is_short\":true,\"text\":{\"content\":\"** 队列类型:** %s\",\"tag\":\"lark_md\"}},{\"is_short\":true,\"text\":{\"content\":\"** 队列容量:** %s\",\"tag\":\"lark_md\"}},{\"is_short\":true,\"text\":{\"content\":\"** 队列元素个数:** %s\",\"tag\":\"lark_md\"}},{\"is_short\":true,\"text\":{\"content\":\"** 队列剩余个数:** %s\",\"tag\":\"lark_md\"}}],\"tag\":\"div\"},{\"tag\":\"hr\"},{\"fields\":[{\"is_short\":true,\"text\":{\"content\":\"** 拒绝策略:** %s\",\"tag\":\"lark_md\"}},{\"is_short\":true,\"text\":{\"content\":\"** 拒绝策略执行次数:** %s\",\"tag\":\"lark_md\"}},{\"is_short\":true,\"text\":{\"content\":\"** OWNER** %s\",\"tag\":\"lark_md\"}},{\"is_short\":true,\"text\":{\"content\":\"** 播报时间: ** %s\",\"tag\":\"lark_md\"}}],\"tag\":\"div\"},{\"tag\":\"hr\"},{\"tag\":\"note\",\"elements\":[{\"tag\":\"plain_text\",\"content\":\"提示: %s 分钟内此线程池不会重复告警(可配置)\"}]}]}}";
public static final String LARK_ALARM_JSON_STR =
"{\"msg_type\":\"interactive\",\"card\":{\"config\":{\"wide_screen_mode\":true},\"header\":{\"template\":\"red\",\"title\":{\"content\":\"[\uD83D\uDD25警报] %s 动态线程池运行告警(%s\",\"tag\":\"plain_text\"}},\"elements\":[{\"fields\":[{\"is_short\":true,\"text\":{\"content\":\"** 线程池ID** %s\",\"tag\":\"lark_md\"}},{\"is_short\":true,\"text\":{\"content\":\"** 应用名称:** %s\",\"tag\":\"lark_md\"}},{\"is_short\":true,\"text\":{\"content\":\"** 应用实例:** %s\",\"tag\":\"lark_md\"}}],\"tag\":\"div\"},{\"tag\":\"hr\"},{\"fields\":[{\"is_short\":true,\"text\":{\"content\":\"** 核心线程数:** %s\",\"tag\":\"lark_md\"}},{\"is_short\":true,\"text\":{\"content\":\"** 最大线程数:** %s\",\"tag\":\"lark_md\"}},{\"is_short\":true,\"text\":{\"content\":\"** 当前线程数:** %s\",\"tag\":\"lark_md\"}},{\"is_short\":true,\"text\":{\"content\":\"** 活跃线程数:** %s\",\"tag\":\"lark_md\"}},{\"is_short\":true,\"text\":{\"content\":\"** 同存最大线程数:** %s\",\"tag\":\"lark_md\"}},{\"is_short\":true,\"text\":{\"content\":\"** 线程池任务总量:** %s\",\"tag\":\"lark_md\"}}],\"tag\":\"div\"},{\"tag\":\"hr\"},{\"fields\":[{\"is_short\":true,\"text\":{\"content\":\"** 队列类型:** %s\",\"tag\":\"lark_md\"}},{\"is_short\":true,\"text\":{\"content\":\"** 队列容量:** %s\",\"tag\":\"lark_md\"}},{\"is_short\":true,\"text\":{\"content\":\"** 队列元素个数:** %s\",\"tag\":\"lark_md\"}},{\"is_short\":true,\"text\":{\"content\":\"** 队列剩余个数:** %s\",\"tag\":\"lark_md\"}}],\"tag\":\"div\"},{\"tag\":\"hr\"},"
+ LARK_ALARM_TIMOUT_REPLACE_TXT
+ "{\"fields\":[{\"is_short\":true,\"text\":{\"content\":\"** 拒绝策略:** %s\",\"tag\":\"lark_md\"}},{\"is_short\":true,\"text\":{\"content\":\"** 拒绝策略执行次数:** %s\",\"tag\":\"lark_md\"}},{\"is_short\":true,\"text\":{\"content\":\"** OWNER** %s\",\"tag\":\"lark_md\"}},{\"is_short\":true,\"text\":{\"content\":\"** 播报时间: ** %s\",\"tag\":\"lark_md\"}}],\"tag\":\"div\"},{\"tag\":\"hr\"},{\"tag\":\"note\",\"elements\":[{\"tag\":\"plain_text\",\"content\":\"提示: %s 分钟内此线程池不会重复告警(可配置)\"}]}]}}";
/**
* lark notice json str
*/
public static final String LARK_NOTICE_JSON_STR = "{\"msg_type\":\"interactive\",\"card\":{\"config\":{\"wide_screen_mode\":true},\"header\":{\"template\":\"greed\",\"title\":{\"content\":\"[通知] %s 动态线程池参数变更\",\"tag\":\"plain_text\"}},\"elements\":[{\"fields\":[{\"is_short\":true,\"text\":{\"content\":\"** 线程池ID** %s\",\"tag\":\"lark_md\"}},{\"is_short\":true,\"text\":{\"content\":\"** 应用名称:** %s\",\"tag\":\"lark_md\"}},{\"is_short\":true,\"text\":{\"content\":\"** 应用实例:** %s\",\"tag\":\"lark_md\"}}],\"tag\":\"div\"},{\"tag\":\"hr\"},{\"fields\":[{\"is_short\":true,\"text\":{\"content\":\"** 核心线程数:** %s\",\"tag\":\"lark_md\"}},{\"is_short\":true,\"text\":{\"content\":\"** 最大线程数:** %s\",\"tag\":\"lark_md\"}},{\"is_short\":true,\"text\":{\"content\":\"** 核心线程超时:** %s\",\"tag\":\"lark_md\"}},{\"is_short\":true,\"text\":{\"content\":\"** 线程存活时间:** %s / SECONDS\",\"tag\":\"lark_md\"}}],\"tag\":\"div\"},{\"tag\":\"hr\"},{\"fields\":[{\"is_short\":true,\"text\":{\"content\":\"** 队列类型:** %s\",\"tag\":\"lark_md\"}},{\"is_short\":true,\"text\":{\"content\":\"** 队列容量:** %s\",\"tag\":\"lark_md\"}}],\"tag\":\"div\"},{\"tag\":\"hr\"},{\"fields\":[{\"is_short\":true,\"text\":{\"content\":\"** AGO 拒绝策略:** %s\",\"tag\":\"lark_md\"}},{\"is_short\":true,\"text\":{\"content\":\"** NOW 拒绝策略执行次数:** %s\",\"tag\":\"lark_md\"}},{\"is_short\":true,\"text\":{\"content\":\"** OWNER** %s\",\"tag\":\"lark_md\"}},{\"is_short\":true,\"text\":{\"content\":\"** 播报时间: ** %s\",\"tag\":\"lark_md\"}}],\"tag\":\"div\"},{\"tag\":\"hr\"},{\"tag\":\"note\",\"elements\":[{\"tag\":\"plain_text\",\"content\":\"提示:动态线程池配置变更实时通知(无限制)\"}]}]}}";
public static final String LARK_NOTICE_JSON_STR =
"{\"msg_type\":\"interactive\",\"card\":{\"config\":{\"wide_screen_mode\":true},\"header\":{\"template\":\"greed\",\"title\":{\"content\":\"[通知] %s 动态线程池参数变更\",\"tag\":\"plain_text\"}},\"elements\":[{\"fields\":[{\"is_short\":true,\"text\":{\"content\":\"** 线程池ID** %s\",\"tag\":\"lark_md\"}},{\"is_short\":true,\"text\":{\"content\":\"** 应用名称:** %s\",\"tag\":\"lark_md\"}},{\"is_short\":true,\"text\":{\"content\":\"** 应用实例:** %s\",\"tag\":\"lark_md\"}}],\"tag\":\"div\"},{\"tag\":\"hr\"},{\"fields\":[{\"is_short\":true,\"text\":{\"content\":\"** 核心线程数:** %s\",\"tag\":\"lark_md\"}},{\"is_short\":true,\"text\":{\"content\":\"** 最大线程数:** %s\",\"tag\":\"lark_md\"}},{\"is_short\":true,\"text\":{\"content\":\"** 核心线程超时:** %s\",\"tag\":\"lark_md\"}},{\"is_short\":true,\"text\":{\"content\":\"** 线程存活时间:** %s\",\"tag\":\"lark_md\"}}],\"tag\":\"div\"},{\"tag\":\"hr\"},{\"fields\":[{\"is_short\":true,\"text\":{\"content\":\"** 队列类型:** %s\",\"tag\":\"lark_md\"}},{\"is_short\":true,\"text\":{\"content\":\"** 队列容量:** %s\",\"tag\":\"lark_md\"}},{\"is_short\":true,\"text\":{\"content\":\"** 执行超时时间:** %s\",\"tag\":\"lark_md\"}}],\"tag\":\"div\"},{\"tag\":\"hr\"},{\"fields\":[{\"is_short\":true,\"text\":{\"content\":\"** AGO 拒绝策略:** %s\",\"tag\":\"lark_md\"}},{\"is_short\":true,\"text\":{\"content\":\"** NOW 拒绝策略:** %s\",\"tag\":\"lark_md\"}},{\"is_short\":true,\"text\":{\"content\":\"** OWNER** %s\",\"tag\":\"lark_md\"}},{\"is_short\":true,\"text\":{\"content\":\"** 播报时间: ** %s\",\"tag\":\"lark_md\"}}],\"tag\":\"div\"},{\"tag\":\"hr\"},{\"tag\":\"note\",\"elements\":[{\"tag\":\"plain_text\",\"content\":\"提示:动态线程池配置变更实时通知(无限制)\"}]}]}}";
}

@ -1,7 +1,25 @@
/*
* 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.notify.platform;
import cn.hippo4j.common.notify.NotifyConfigDTO;
import cn.hippo4j.common.notify.NotifyPlatformEnum;
import cn.hippo4j.common.notify.NotifyTypeEnum;
import cn.hippo4j.common.notify.SendMessageHandler;
import cn.hippo4j.common.notify.request.AlarmNotifyRequest;
import cn.hippo4j.common.notify.request.ChangeParameterNotifyRequest;
@ -14,15 +32,13 @@ import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import java.util.Arrays;
import java.util.Objects;
import java.util.stream.Collectors;
import static cn.hippo4j.common.notify.platform.LarkAlarmConstants.*;
/**
* Send lark notification message.
*
* @author imyzt
* @date 2021/11/22 21:12
*/
@Slf4j
@AllArgsConstructor
@ -36,20 +52,34 @@ public class LarkSendMessageHandler implements SendMessageHandler<AlarmNotifyReq
@Override
@SneakyThrows
public void sendAlarmMessage(NotifyConfigDTO notifyConfig, AlarmNotifyRequest alarmNotifyRequest) {
String afterReceives = getReceives(alarmNotifyRequest.getReceives());
String larkAlarmJson = LARK_ALARM_JSON_STR;
String afterReceives = getReceives(notifyConfig.getReceives());
String larkAlarmTxt;
String larkAlarmTimoutReplaceTxt;
if (Objects.equals(alarmNotifyRequest.getNotifyTypeEnum(), NotifyTypeEnum.TIMEOUT)) {
String executeTimeoutTrace = alarmNotifyRequest.getExecuteTimeoutTrace();
if (StringUtil.isNotBlank(executeTimeoutTrace)) {
String larkAlarmTimoutTraceReplaceTxt = String.format(LARK_ALARM_TIMOUT_TRACE_REPLACE_TXT, executeTimeoutTrace);
larkAlarmTimoutReplaceTxt = StrUtil.replace(LARK_ALARM_TIMOUT_REPLACE_TXT, LARK_ALARM_TIMOUT_TRACE_REPLACE_TXT, larkAlarmTimoutTraceReplaceTxt);
} else {
larkAlarmTimoutReplaceTxt = StrUtil.replace(LARK_ALARM_TIMOUT_REPLACE_TXT, LARK_ALARM_TIMOUT_TRACE_REPLACE_TXT, "");
}
larkAlarmTimoutReplaceTxt = String.format(larkAlarmTimoutReplaceTxt, alarmNotifyRequest.getExecuteTime(), alarmNotifyRequest.getExecuteTimeOut());
larkAlarmTxt = StrUtil.replace(LARK_ALARM_JSON_STR, LARK_ALARM_TIMOUT_REPLACE_TXT, larkAlarmTimoutReplaceTxt);
} else {
larkAlarmTxt = StrUtil.replace(LARK_ALARM_JSON_STR, LARK_ALARM_TIMOUT_REPLACE_TXT, "");
}
String text = String.format(larkAlarmJson,
String text = String.format(larkAlarmTxt,
// 环境
alarmNotifyRequest.getActive(),
// 报警类型
alarmNotifyRequest.getNotifyTypeEnum(),
// 线程池ID
alarmNotifyRequest.getThreadPoolId(),
// 应用名称
alarmNotifyRequest.getAppName(),
// 实例信息
alarmNotifyRequest.getIdentify(),
// 报警类型
notifyConfig.getTypeEnum(),
// 核心线程数
alarmNotifyRequest.getCorePoolSize(),
// 最大线程数
@ -79,9 +109,7 @@ public class LarkSendMessageHandler implements SendMessageHandler<AlarmNotifyReq
// 当前时间
DateUtil.now(),
// 报警频率
notifyConfig.getInterval()
);
notifyConfig.getInterval());
execute(notifyConfig.getSecretKey(), text);
}
@ -91,10 +119,6 @@ public class LarkSendMessageHandler implements SendMessageHandler<AlarmNotifyReq
String threadPoolId = changeParameterNotifyRequest.getThreadPoolId();
String afterReceives = getReceives(notifyConfig.getReceives());
String larkNoticeJson = LARK_NOTICE_JSON_STR;
/**
* hesitant e.g.
*/
String text = String.format(larkNoticeJson,
// 环境
changeParameterNotifyRequest.getActive(),
@ -116,15 +140,15 @@ public class LarkSendMessageHandler implements SendMessageHandler<AlarmNotifyReq
changeParameterNotifyRequest.getBlockingQueueName(),
// 阻塞队列容量
changeParameterNotifyRequest.getBeforeQueueCapacity() + " ➲ " + changeParameterNotifyRequest.getNowQueueCapacity(),
// 执行超时时间
changeParameterNotifyRequest.getBeforeExecuteTimeOut() + " ➲ " + changeParameterNotifyRequest.getNowExecuteTimeOut(),
// 拒绝策略
changeParameterNotifyRequest.getBeforeRejectedName(),
changeParameterNotifyRequest.getNowRejectedName(),
// 告警手机号
afterReceives,
// 当前时间
DateUtil.now()
);
DateUtil.now());
execute(notifyConfig.getSecretKey(), text);
}
@ -133,19 +157,16 @@ public class LarkSendMessageHandler implements SendMessageHandler<AlarmNotifyReq
return "";
}
return Arrays.stream(receives.split(","))
.map(receive -> StrUtil.startWith(receive, LARK_OPENID_PREFIX) ?
String.format(LARK_AT_FORMAT_OPENID, receive) : String.format(LARK_AT_FORMAT_USERNAME, receive))
.map(receive -> StrUtil.startWith(receive, LARK_OPENID_PREFIX) ? String.format(LARK_AT_FORMAT_OPENID, receive) : String.format(LARK_AT_FORMAT_USERNAME, receive))
.collect(Collectors.joining(" "));
}
private void execute(String secretKey, String text) {
String serverUrl = LARK_BOT_URL + secretKey;
try {
HttpRequest.post(serverUrl).body(text).execute();
} catch (Exception ex) {
log.error("Lark failed to send message", ex);
}
}
}

@ -1,10 +1,24 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package cn.hippo4j.common.notify.platform;
/**
* Ding alarm constants.
*
* @author chen.ma
* @date 2021/11/26 20:03
* We chat alarm constants.
*/
public class WeChatAlarmConstants {
@ -13,27 +27,40 @@ public class WeChatAlarmConstants {
*/
public static final String WE_CHAT_SERVER_URL = "https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=";
/**
* Trace
*/
public static final String WE_CHAT_ALARM_TIMOUT_TRACE_REPLACE_TXT = "> 链路信息:%s \n";
/**
*
*/
public static final String WE_CHAT_ALARM_TIMOUT_REPLACE_TXT =
"> 任务执行时间:%s / ms \n" +
"> 超时时间:%s / ms \n" +
WE_CHAT_ALARM_TIMOUT_TRACE_REPLACE_TXT;
/**
* 线
*/
public static final String WE_CHAT_ALARM_TXT =
"### <font color='#FF0000'>[警报] </font>%s - 动态线程池运行告警 \n" +
"### <font color='#FF0000'>[警报] </font>%s - 动态线程池运行告警%s \n" +
"> 线程池ID<font color=\"warning\">%s</font> \n" +
"> 应用名称:<font color=\"warning\">%s</font> \n" +
"> 应用实例:%s \n" +
"> 报警类型:%s \n" +
"> 核心线程数:%s \n" +
"> 最大线程数:%s \n" +
"> 当前线程数:%s \n" +
"> 活跃线程数:%s \n" +
"> 最大任务数:%s \n" +
"> 同存最大线程数:%s \n" +
"> 线程池任务总量:%s \n" +
"> 队列类型:%s \n" +
"> 队列容量:%s \n" +
"> 队列元素个数:%s \n" +
"> 队列剩余个数:%s \n" +
"> 拒绝策略:%s \n" +
"> 拒绝策略执行次数:%s \n" +
"> 拒绝策略执行次数:<font color='#FF0000'>%s</font> \n" +
WE_CHAT_ALARM_TIMOUT_REPLACE_TXT +
"> OWNER<@%s> \n" +
"> 提示:%d 分钟内此线程池不会重复告警(可配置) \n\n" +
"**播报时间:%s**";
@ -49,7 +76,8 @@ public class WeChatAlarmConstants {
"> 核心线程数:%s \n" +
"> 最大线程数:%s \n" +
"> 核心线程超时:%s \n" +
"> 线程存活时间:%s / SECONDS \n" +
"> 线程存活时间:%s \n" +
"> 执行超时时间:%s \n" +
"> 队列类型:%s \n" +
"> 队列容量:%s \n" +
"> AGO 拒绝策略:%s \n" +
@ -57,5 +85,4 @@ public class WeChatAlarmConstants {
"> OWNER<@%s> \n" +
"> 提示:动态线程池配置变更实时通知(无限制) \n\n" +
"**播报时间:%s**";
}

@ -1,25 +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.notify.platform;
import cn.hippo4j.common.notify.NotifyConfigDTO;
import cn.hippo4j.common.notify.NotifyPlatformEnum;
import cn.hippo4j.common.notify.SendMessageHandler;
import cn.hippo4j.common.notify.*;
import cn.hippo4j.common.notify.request.AlarmNotifyRequest;
import cn.hippo4j.common.notify.request.ChangeParameterNotifyRequest;
import cn.hippo4j.common.toolkit.JSONUtil;
import cn.hippo4j.common.toolkit.StringUtil;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.http.HttpRequest;
import com.google.common.base.Joiner;
import lombok.Data;
import lombok.experimental.Accessors;
import lombok.extern.slf4j.Slf4j;
import java.util.Objects;
import static cn.hippo4j.common.notify.platform.WeChatAlarmConstants.*;
/**
* WeChat send message handler.
*
* @author chen.ma
* @date 2021/11/26 20:06
*/
@Slf4j
public class WeChatSendMessageHandler implements SendMessageHandler<AlarmNotifyRequest, ChangeParameterNotifyRequest> {
@ -33,19 +49,34 @@ public class WeChatSendMessageHandler implements SendMessageHandler<AlarmNotifyR
public void sendAlarmMessage(NotifyConfigDTO notifyConfig, AlarmNotifyRequest alarmNotifyRequest) {
String[] receives = notifyConfig.getReceives().split(",");
String afterReceives = Joiner.on("><@").join(receives);
String weChatAlarmTxt;
String weChatAlarmTimoutReplaceTxt;
if (Objects.equals(alarmNotifyRequest.getNotifyTypeEnum(), NotifyTypeEnum.TIMEOUT)) {
String executeTimeoutTrace = alarmNotifyRequest.getExecuteTimeoutTrace();
if (StringUtil.isNotBlank(executeTimeoutTrace)) {
String weChatAlarmTimoutTraceReplaceTxt = String.format(WE_CHAT_ALARM_TIMOUT_TRACE_REPLACE_TXT, executeTimeoutTrace);
weChatAlarmTimoutReplaceTxt = StrUtil.replace(WE_CHAT_ALARM_TIMOUT_REPLACE_TXT, WE_CHAT_ALARM_TIMOUT_TRACE_REPLACE_TXT, weChatAlarmTimoutTraceReplaceTxt);
} else {
weChatAlarmTimoutReplaceTxt = StrUtil.replace(WE_CHAT_ALARM_TIMOUT_REPLACE_TXT, WE_CHAT_ALARM_TIMOUT_TRACE_REPLACE_TXT, "");
}
weChatAlarmTimoutReplaceTxt = String.format(weChatAlarmTimoutReplaceTxt, alarmNotifyRequest.getExecuteTime(), alarmNotifyRequest.getExecuteTimeOut());
weChatAlarmTxt = StrUtil.replace(WE_CHAT_ALARM_TXT, WE_CHAT_ALARM_TIMOUT_REPLACE_TXT, weChatAlarmTimoutReplaceTxt);
} else {
weChatAlarmTxt = StrUtil.replace(WE_CHAT_ALARM_TXT, WE_CHAT_ALARM_TIMOUT_REPLACE_TXT, "");
}
String text = String.format(
WE_CHAT_ALARM_TXT,
weChatAlarmTxt,
// 环境
alarmNotifyRequest.getActive(),
// 报警类型
alarmNotifyRequest.getNotifyTypeEnum(),
// 线程池ID
alarmNotifyRequest.getThreadPoolId(),
// 应用名称
alarmNotifyRequest.getAppName(),
// 实例信息
alarmNotifyRequest.getIdentify(),
// 报警类型
notifyConfig.getTypeEnum(),
// 核心线程数
alarmNotifyRequest.getCorePoolSize(),
// 最大线程数
@ -75,18 +106,15 @@ public class WeChatSendMessageHandler implements SendMessageHandler<AlarmNotifyR
// 报警频率
notifyConfig.getInterval(),
// 当前时间
DateUtil.now()
);
DateUtil.now());
execute(notifyConfig.getSecretKey(), text);
}
@Override
public void sendChangeMessage(NotifyConfigDTO notifyConfig, ChangeParameterNotifyRequest changeParameterNotifyRequest) {
String threadPoolId = changeParameterNotifyRequest.getThreadPoolId();
String[] receives = notifyConfig.getReceives().split(",");
String afterReceives = Joiner.on("><@").join(receives);
String text = String.format(
WE_CHAT_NOTICE_TXT,
// 环境
@ -105,6 +133,8 @@ public class WeChatSendMessageHandler implements SendMessageHandler<AlarmNotifyR
changeParameterNotifyRequest.getBeforeAllowsCoreThreadTimeOut() + " ➲ " + changeParameterNotifyRequest.getNowAllowsCoreThreadTimeOut(),
// 线程存活时间
changeParameterNotifyRequest.getBeforeKeepAliveTime() + " ➲ " + changeParameterNotifyRequest.getNowKeepAliveTime(),
// 执行超时时间
changeParameterNotifyRequest.getBeforeExecuteTimeOut() + " ➲ " + changeParameterNotifyRequest.getNowExecuteTimeOut(),
// 阻塞队列
changeParameterNotifyRequest.getBlockingQueueName(),
// 阻塞队列容量
@ -115,9 +145,7 @@ public class WeChatSendMessageHandler implements SendMessageHandler<AlarmNotifyR
// 告警手机号
afterReceives,
// 当前时间
DateUtil.now()
);
DateUtil.now());
execute(notifyConfig.getSecretKey(), text);
}
@ -129,15 +157,12 @@ public class WeChatSendMessageHandler implements SendMessageHandler<AlarmNotifyR
*/
private void execute(String secretKey, String text) {
String serverUrl = WE_CHAT_SERVER_URL + secretKey;
try {
WeChatReqDTO weChatReq = new WeChatReqDTO();
weChatReq.setMsgtype("markdown");
Markdown markdown = new Markdown();
markdown.setContent(text);
weChatReq.setMarkdown(markdown);
HttpRequest.post(serverUrl).body(JSONUtil.toJSONString(weChatReq)).execute();
} catch (Exception ex) {
log.error("WeChat failed to send message", ex);
@ -148,26 +173,14 @@ public class WeChatSendMessageHandler implements SendMessageHandler<AlarmNotifyR
@Accessors(chain = true)
public static class WeChatReqDTO {
/**
* msgType
*/
private String msgtype;
/**
* markdown
*/
private Markdown markdown;
}
@Data
public static class Markdown {
/**
* content
*/
private String content;
}
}

@ -1,3 +1,20 @@
/*
* 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.notify.request;
import cn.hippo4j.common.notify.NotifyTypeEnum;
@ -7,9 +24,6 @@ import lombok.experimental.Accessors;
/**
* Alarm notify request.
*
* @author chen.ma
* @date 2022/2/22 19:41
*/
@Data
@Accessors(chain = true)
@ -25,34 +39,93 @@ public class AlarmNotifyRequest extends BaseNotifyRequest {
*/
private NotifyTypeEnum notifyTypeEnum;
/**
* active
*/
private String active;
/**
* appName
*/
private String appName;
/**
* identify
*/
private String identify;
/**
* corePoolSize
*/
private Integer corePoolSize;
/**
* maximumPoolSize
*/
private Integer maximumPoolSize;
/**
* poolSize
*/
private Integer poolSize;
/**
* activeCount
*/
private Integer activeCount;
/**
* largestPoolSize
*/
private Integer largestPoolSize;
/**
* completedTaskCount
*/
private Long completedTaskCount;
/**
* queueName
*/
private String queueName;
/**
* capacity
*/
private Integer capacity;
/**
* queueSize
*/
private Integer queueSize;
/**
* remainingCapacity
*/
private Integer remainingCapacity;
/**
* rejectedExecutionHandlerName
*/
private String rejectedExecutionHandlerName;
/**
* rejectCountNum
*/
private Long rejectCountNum;
/**
* executeTime
*/
private Long executeTime;
/**
* executeTimeOut
*/
private Long executeTimeOut;
/**
* executeTimeoutTrace
*/
private String executeTimeoutTrace;
}

@ -1,3 +1,20 @@
/*
* 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.notify.request;
import cn.hippo4j.common.notify.request.base.BaseNotifyRequest;
@ -5,9 +22,6 @@ import lombok.Data;
/**
* Change parameter notify request.
*
* @author chen.ma
* @date 2022/2/22 20:22
*/
@Data
public class ChangeParameterNotifyRequest extends BaseNotifyRequest {
@ -34,6 +48,10 @@ public class ChangeParameterNotifyRequest extends BaseNotifyRequest {
private Long nowKeepAliveTime;
private Long beforeExecuteTimeOut;
private Long nowExecuteTimeOut;
private String blockingQueueName;
private Integer beforeQueueCapacity;
@ -43,5 +61,4 @@ public class ChangeParameterNotifyRequest extends BaseNotifyRequest {
private String beforeRejectedName;
private String nowRejectedName;
}

@ -1,12 +1,26 @@
/*
* 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.notify.request;
import lombok.Data;
/**
* Robot alarm notify request.
*
* @author chen.ma
* @date 2022/2/22 21:50
*/
@Data
public class RobotAlarmNotifyRequest extends AlarmNotifyRequest {
@ -15,5 +29,4 @@ public class RobotAlarmNotifyRequest extends AlarmNotifyRequest {
* secretKey
*/
private String secretKey;
}

@ -1,12 +1,26 @@
/*
* 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.notify.request;
import lombok.Data;
/**
* Robot change parameter notify request.
*
* @author chen.ma
* @date 2022/2/22 21:03
*/
@Data
public class RobotChangeParameterNotifyRequest extends ChangeParameterNotifyRequest {
@ -15,5 +29,4 @@ public class RobotChangeParameterNotifyRequest extends ChangeParameterNotifyRequ
* secretKey
*/
private String secretKey;
}

@ -1,3 +1,20 @@
/*
* 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.notify.request;
import lombok.AllArgsConstructor;
@ -7,9 +24,6 @@ import java.util.List;
/**
* Thread pool notify request.
*
* @author chen.ma
* @date 2022/2/24 19:06
*/
@Data
@AllArgsConstructor
@ -19,5 +33,4 @@ public class ThreadPoolNotifyRequest {
* groupKeys
*/
private List<String> groupKeys;
}

@ -1,12 +1,26 @@
/*
* 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.notify.request.base;
import lombok.Data;
/**
* Base notify request.
*
* @author chen.ma
* @date 2022/2/22 19:35
*/
@Data
public class BaseNotifyRequest implements NotifyRequest {
@ -40,5 +54,4 @@ public class BaseNotifyRequest implements NotifyRequest {
* receives
*/
private String receives;
}

@ -1,10 +1,24 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package cn.hippo4j.common.notify.request.base;
/**
* Notify request.
*
* @author chen.ma
* @date 2022/2/22 19:38
*/
public interface NotifyRequest {
}

@ -1,3 +1,20 @@
/*
* 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.toolkit;
import cn.hippo4j.common.function.Matcher;
@ -6,9 +23,6 @@ import java.lang.reflect.Array;
/**
* Array util.
*
* @author chen.ma
* @date 2021/12/30 21:42
*/
public class ArrayUtil {
@ -34,7 +48,6 @@ public class ArrayUtil {
return !isEmpty(array);
}
/**
* First match.
*
@ -51,7 +64,6 @@ public class ArrayUtil {
}
}
}
return null;
}
@ -70,7 +82,8 @@ public class ArrayUtil {
return clone(array1);
}
final Class<?> type1 = array1.getClass().getComponentType();
@SuppressWarnings("unchecked") final T[] joinedArray = (T[]) Array.newInstance(type1, array1.length + array2.length);
@SuppressWarnings("unchecked")
final T[] joinedArray = (T[]) Array.newInstance(type1, array1.length + array2.length);
System.arraycopy(array1, 0, joinedArray, 0, array1.length);
try {
System.arraycopy(array2, 0, joinedArray, array1.length, array2.length);
@ -98,5 +111,4 @@ public class ArrayUtil {
}
return array.clone();
}
}

@ -1,3 +1,20 @@
/*
* 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.toolkit;
import org.springframework.util.CollectionUtils;
@ -8,9 +25,6 @@ import java.util.Map;
/**
* Assert.
*
* @author chen.ma
* @date 2021/6/29 09:36
*/
public class Assert {

@ -1,3 +1,20 @@
/*
* 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.toolkit;
import java.util.Collection;
@ -7,9 +24,6 @@ import java.util.Map;
/**
* Collection util.
*
* @author chen.ma
* @date 2021/12/22 20:43
*/
public class CollectionUtil {
@ -49,7 +63,6 @@ public class CollectionUtil {
return !isEmpty(list);
}
/**
* Is empty.
*
@ -109,5 +122,4 @@ public class CollectionUtil {
public static boolean isNotEmpty(Collection<?> collection) {
return !isEmpty(collection);
}
}

@ -1,12 +1,26 @@
/*
* 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.toolkit;
import cn.hippo4j.common.function.NoArgsConsumer;
/**
* Condition util.
*
* @author chen.ma
* @date 2021/11/6 22:40
*/
public class ConditionUtil {
@ -17,5 +31,4 @@ public class ConditionUtil {
falseConsumer.accept();
}
}
}

@ -1,20 +1,34 @@
/*
* 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.toolkit;
import cn.hippo4j.common.constant.Constants;
import cn.hippo4j.common.model.PoolParameter;
import cn.hippo4j.common.model.PoolParameterInfo;
import cn.hippo4j.common.model.ThreadPoolParameter;
import cn.hippo4j.common.model.ThreadPoolParameterInfo;
/**
* Content util.
*
* @author chen.ma
* @date 2021/6/24 16:13
*/
public class ContentUtil {
public static String getPoolContent(PoolParameter parameter) {
PoolParameterInfo poolInfo = new PoolParameterInfo();
poolInfo.setTenantId(parameter.getTenantId())
public static String getPoolContent(ThreadPoolParameter parameter) {
ThreadPoolParameterInfo threadPoolParameterInfo = new ThreadPoolParameterInfo();
threadPoolParameterInfo.setTenantId(parameter.getTenantId())
.setItemId(parameter.getItemId())
.setTpId(parameter.getTpId())
.setCoreSize(parameter.getCoreSize())
@ -27,10 +41,10 @@ public class ContentUtil {
.setLivenessAlarm(parameter.getLivenessAlarm())
.setAllowCoreThreadTimeOut(parameter.getAllowCoreThreadTimeOut())
.setRejectedType(parameter.getRejectedType());
return JSONUtil.toJSONString(poolInfo);
return JSONUtil.toJSONString(threadPoolParameterInfo);
}
public static String getGroupKey(PoolParameter parameter) {
public static String getGroupKey(ThreadPoolParameter parameter) {
StringBuilder stringBuilder = new StringBuilder();
String resultStr = stringBuilder.append(parameter.getTpId())
.append(Constants.GROUP_KEY_DELIMITER)
@ -45,13 +59,10 @@ public class ContentUtil {
StringBuilder stringBuilder = new StringBuilder();
for (int i = 0; i < parameters.length; i++) {
stringBuilder.append(parameters[i]);
if (i < parameters.length - 1) {
stringBuilder.append(Constants.GROUP_KEY_DELIMITER);
}
}
return stringBuilder.toString();
}
}

@ -1,3 +1,20 @@
/*
* 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.toolkit;
import cn.hippo4j.common.constant.Constants;
@ -7,9 +24,6 @@ import static cn.hippo4j.common.constant.Constants.GROUP_KEY_DELIMITER;
/**
* Group key.
*
* @author chen.ma
* @date 2021/6/24 21:12
*/
public class GroupKey {
@ -24,11 +38,9 @@ public class GroupKey {
public static String getKey(String... params) {
StringBuilder groupKey = new StringBuilder();
groupKey.append(params[0]).append(GROUP_KEY_DELIMITER);
for (int i = 1; i < params.length - 1; i++) {
groupKey.append(params[i]).append(GROUP_KEY_DELIMITER);
}
groupKey.append(params[params.length]);
return groupKey.toString();
}
@ -46,7 +58,6 @@ public class GroupKey {
sb.append(GROUP_KEY_DELIMITER);
urlEncode(datumStr, sb);
}
return sb.toString();
}
@ -66,5 +77,4 @@ public class GroupKey {
}
}
}
}

@ -1,3 +1,20 @@
/*
* 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.toolkit;
import cn.hippo4j.common.api.JsonFacade;
@ -6,9 +23,6 @@ import java.util.List;
/**
* JSON util.
*
* @author chen.ma
* @date 2021/12/13 20:27
*/
public class JSONUtil {
@ -37,5 +51,4 @@ public class JSONUtil {
return JSON_FACADE.parseArray(text, clazz);
}
}

@ -1,3 +1,20 @@
/*
* 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.toolkit;
import cn.hippo4j.common.api.JsonFacade;
@ -16,9 +33,6 @@ import java.util.List;
/**
* Jackson util.
*
* @author chen.ma
* @date 2021/12/13 20:02
*/
public class JacksonHandler implements JsonFacade {
@ -53,5 +67,4 @@ public class JacksonHandler implements JsonFacade {
CollectionType collectionType = MAPPER.getTypeFactory().constructCollectionType(ArrayList.class, clazz);
return MAPPER.readValue(text, collectionType);
}
}

@ -1,7 +1,24 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package cn.hippo4j.common.toolkit;
import cn.hippo4j.common.constant.Constants;
import cn.hippo4j.common.model.PoolParameter;
import cn.hippo4j.common.model.ThreadPoolParameter;
import java.io.IOException;
import java.net.URLEncoder;
@ -11,9 +28,6 @@ import java.util.List;
/**
* MD5 util.
*
* @author chen.ma
* @date 2021/6/22 17:55
*/
public class Md5Util {
@ -50,16 +64,14 @@ public class Md5Util {
public static String encodeHexString(byte[] bytes) {
int l = bytes.length;
char[] out = new char[l << 1];
for (int i = 0, j = 0; i < l; i++) {
out[j++] = DIGITS_LOWER[(0xF0 & bytes[i]) >>> 4];
out[j++] = DIGITS_LOWER[0x0F & bytes[i]];
}
return new String(out);
}
public static String getTpContentMd5(PoolParameter config) {
public static String getTpContentMd5(ThreadPoolParameter config) {
return Md5Util.md5Hex(ContentUtil.getPoolContent(config), "UTF-8");
}
@ -67,9 +79,7 @@ public class Md5Util {
if (null == changedGroupKeys) {
return "";
}
StringBuilder sb = new StringBuilder();
for (String groupKey : changedGroupKeys) {
String[] dataIdGroupId = GroupKey.parseKey(groupKey);
sb.append(dataIdGroupId[0]);
@ -89,9 +99,7 @@ public class Md5Util {
}
sb.append(Constants.LINE_SEPARATOR);
}
// To encode WORD_SEPARATOR and LINE_SEPARATOR invisible characters, encoded value is %02 and %01
return URLEncoder.encode(sb.toString(), "UTF-8");
}
}

Some files were not shown because too many files have changed in this diff Show More

Loading…
Cancel
Save