Optimize code format and delete meaningless blank lines

pull/218/head
chen.ma 2 years ago
parent 7cb555804e
commit b1332ab587

@ -43,7 +43,7 @@ import javax.annotation.Resource;
import java.util.stream.Stream;
/**
* .
* Global security config.
*
* @author chen.ma
* @date 2021/11/9 21:10
@ -108,5 +108,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);
}
}

@ -30,5 +30,4 @@ public class Constants {
public static final String SPLIT_COMMA = ",";
public static final long TOKEN_VALIDITY_IN_SECONDS = 18000L;
}

@ -67,7 +67,7 @@ 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());
@ -87,13 +87,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");
@ -111,5 +109,4 @@ public class JWTAuthenticationFilter extends UsernamePasswordAuthenticationFilte
response.setCharacterEncoding("UTF-8");
response.getWriter().write(JSONUtil.toJsonStr(new ReturnT(-1, "Server Error")));
}
}

@ -62,30 +62,27 @@ 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");
String resultStatus = "-1";
@ -97,7 +94,6 @@ public class JWTAuthorizationFilter extends BasicAuthenticationFilter {
response.getWriter().flush();
return;
}
try {
super.doFilterInternal(request, response, chain);
} finally {
@ -106,7 +102,7 @@ public class JWTAuthorizationFilter extends BasicAuthenticationFilter {
}
/**
* Token Token.
* Obtain user information from Token and create a new Token.
*
* @param tokenHeader
* @return
@ -117,18 +113,14 @@ public class JWTAuthorizationFilter extends BasicAuthenticationFilter {
if (expiration) {
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)));
}
return null;
}
}

@ -71,5 +71,4 @@ public class PermissionInfo {
@TableLogic
@TableField(fill = FieldFill.INSERT)
private Integer delFlag;
}

@ -66,5 +66,4 @@ public class RoleInfo {
@TableLogic
@TableField(fill = FieldFill.INSERT)
private Integer delFlag;
}

@ -71,5 +71,4 @@ public class UserInfo {
@TableLogic
@TableField(fill = FieldFill.INSERT)
private Integer delFlag;
}

@ -32,5 +32,4 @@ public class PermissionQueryPageReqDTO extends Page {
public PermissionQueryPageReqDTO(long current, long size) {
super(current, size);
}
}

@ -42,5 +42,4 @@ public class PermissionRespDTO {
* action
*/
private String action;
}

@ -32,5 +32,4 @@ public class RoleQueryPageReqDTO extends Page {
public RoleQueryPageReqDTO(long current, long size) {
super(current, size);
}
}

@ -37,5 +37,4 @@ public class RoleRespDTO {
* userName
*/
private String userName;
}

@ -71,5 +71,4 @@ public class JwtUser implements UserDetails {
public boolean isEnabled() {
return true;
}
}

@ -42,5 +42,4 @@ public class LoginUser {
* rememberMe
*/
private Integer rememberMe;
}

@ -35,5 +35,4 @@ public class UserQueryPageReqDTO extends Page {
* userName
*/
private String userName;
}

@ -45,5 +45,4 @@ public class UserReqDTO extends Page {
* role
*/
private String role;
}

@ -52,5 +52,4 @@ public class UserRespDTO {
*/
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
private Date gmtModified;
}

@ -56,8 +56,6 @@ public class AuthManager {
} catch (AuthenticationException e) {
throw new AccessException("Unknown user.");
}
return jwtTokenManager.createToken(userName);
}
}

@ -46,10 +46,8 @@ 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();
@ -67,12 +65,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);
}
}

@ -29,7 +29,7 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
public interface PermissionService {
/**
* .
* Paging query permission list.
*
* @param pageNo
* @param pageSize
@ -38,7 +38,7 @@ public interface PermissionService {
IPage<PermissionRespDTO> listPermission(int pageNo, int pageSize);
/**
* .
* Add permission.
*
* @param role
* @param resource
@ -47,12 +47,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);
}

@ -31,7 +31,7 @@ import java.util.List;
public interface RoleService {
/**
* .
* Paging query role list.
*
* @param pageNo
* @param pageSize
@ -40,7 +40,7 @@ public interface RoleService {
IPage<RoleRespDTO> listRole(int pageNo, int pageSize);
/**
* .
* Add role.
*
* @param role
* @param userName
@ -48,7 +48,7 @@ public interface RoleService {
void addRole(String role, String userName);
/**
* .
* Delete role.
*
* @param role
* @param userName
@ -56,11 +56,10 @@ public interface RoleService {
void deleteRole(String role, String userName);
/**
* .
* Fuzzy search by role.
*
* @param role
* @return
*/
List<String> getRoleLike(String role);
}

@ -33,7 +33,7 @@ import java.util.List;
public interface UserService {
/**
* .
* Paging query user list.
*
* @param reqDTO
* @return
@ -41,28 +41,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
@ -70,11 +70,10 @@ public interface UserService {
List<String> getUserLikeUsername(String userName);
/**
* .
* Get user details.
*
* @param reqDTO
* @return
*/
UserRespDTO getUser(UserReqDTO reqDTO);
}

@ -61,7 +61,6 @@ public class PermissionServiceImpl implements PermissionService {
if (existPermissionInfo != null) {
throw new RuntimeException("权限重复");
}
PermissionInfo insertPermission = new PermissionInfo();
insertPermission.setRole(role);
insertPermission.setResource(resource);
@ -75,8 +74,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);
}
}

@ -54,7 +54,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));
}
@ -66,7 +65,6 @@ public class RoleServiceImpl implements RoleService {
if (roleInfo != null) {
throw new RuntimeException("角色名重复");
}
RoleInfo insertRole = new RoleInfo();
insertRole.setRole(role);
insertRole.setUserName(userName);
@ -80,12 +78,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, "", ""));
}
@ -94,11 +90,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;
}
}

@ -44,16 +44,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;
}
}

@ -62,7 +62,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));
}
@ -74,7 +73,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);
@ -86,7 +84,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);
@ -97,7 +94,6 @@ public class UserServiceImpl implements UserService {
LambdaUpdateWrapper<UserInfo> updateWrapper = Wrappers.lambdaUpdate(UserInfo.class)
.eq(UserInfo::getUserName, userName);
userMapper.delete(updateWrapper);
// roleService.deleteRole("", userName);
}
@Override
@ -105,10 +101,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;
}
@ -116,11 +110,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;
}
}

@ -45,22 +45,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
@ -83,7 +83,7 @@ public class JwtTokenUtil {
}
/**
* Token .
* Get the username from Token.
*
* @param token
* @return
@ -94,7 +94,7 @@ public class JwtTokenUtil {
}
/**
* Token .
* Get the username from Token.
*
* @param token
* @return
@ -105,7 +105,7 @@ public class JwtTokenUtil {
}
/**
* .
* Get user role.
*
* @param token
* @return
@ -115,7 +115,7 @@ public class JwtTokenUtil {
}
/**
* .
* Has it expired.
*
* @param token
* @return
@ -131,5 +131,4 @@ public class JwtTokenUtil {
private static Claims getTokenBody(String token) {
return Jwts.parser().setSigningKey(SECRET).parseClaimsJws(token).getBody();
}
}

@ -53,5 +53,4 @@ public class ReturnT<T> implements Serializable {
this.code = SUCCESS_CODE;
this.content = content;
}
}

@ -51,7 +51,6 @@ public class GlobalExceptionHandler {
log.error("[{}] {} [ex] {}", request.getMethod(), request.getRequestURL().toString(), ex.toString(), ex.getCause());
return Results.failure(ex);
}
log.info("[{}] {} [ex] {}", request.getMethod(), request.getRequestURL().toString(), ex.toString());
return Results.failure(ex);
}
@ -64,7 +63,6 @@ public class GlobalExceptionHandler {
String exceptionStr = Optional.ofNullable(firstFieldError)
.map(FieldError::getDefaultMessage)
.orElse(StringUtil.EMPTY);
log.error("[{}] {} [ex] {}", request.getMethod(), getUrl(request), exceptionStr);
return Results.failure(new ServiceException(exceptionStr));
}
@ -79,8 +77,6 @@ public class GlobalExceptionHandler {
if (StringUtils.isEmpty(request.getQueryString())) {
return request.getRequestURL().toString();
}
return request.getRequestURL().toString() + "?" + request.getQueryString();
}
}

@ -35,5 +35,4 @@ public class WebConfig implements WebMvcConfigurer {
registry.addResourceHandler("/index.html").addResourceLocations("classpath:/static/index.html");
registry.addResourceHandler("/static/**").addResourceLocations("classpath:/static/static/");
}
}

@ -45,5 +45,4 @@ public class ClientCloseHookController {
clientCloseHookExecuteMap.forEach((key, execute) -> execute.closeHook(req));
return Results.success();
}
}

@ -68,5 +68,4 @@ public class DashboardController {
RankingChart rankingChart = dashboardService.getRankingChart();
return Results.success(rankingChart);
}
}

@ -44,5 +44,4 @@ public class HealthCheckController {
public Result<String> healthCheck() {
return Results.success(UP);
}
}

@ -70,5 +70,4 @@ public class ItemController {
itemService.deleteItem(tenantId, itemId);
return Results.success();
}
}

@ -47,5 +47,4 @@ public class LogRecordController {
public Result<IPage<LogRecordRespDTO>> queryPage(@RequestBody LogRecordQueryReqDTO queryReqDTO) {
return Results.success(logRecordBizService.queryPage(queryReqDTO));
}
}

@ -77,14 +77,11 @@ public class MonitorController {
Message message = MessageConvert.convert(messageWrapper);
queryMonitorExecuteChoose.chooseAndExecute(message);
};
try {
monitorThreadPoolTaskExecutor.execute(task);
} catch (Exception ex) {
log.error("Monitoring data insertion database task overflow.", ex);
}
return Results.success();
}
}

@ -79,5 +79,4 @@ public class NotifyController {
notifyService.enableNotify(id, status);
return Results.success();
}
}

@ -55,5 +55,4 @@ public class PermissionController {
permissionService.deletePermission(role, resource, action);
return Results.success();
}
}

@ -63,5 +63,4 @@ public class RoleController {
List<String> resultRole = roleService.getRoleLike(role);
return Results.success(resultRole);
}
}

@ -71,5 +71,4 @@ public class TenantController {
tenantService.deleteTenantById(tenantId);
return Results.success(Boolean.TRUE);
}
}

@ -147,7 +147,6 @@ public class ThreadPoolController {
if (first == null) {
return Results.success(Lists.newArrayList());
}
InstanceInfo holder = first.getHolder();
String itemTenantKey = holder.getGroupKey();
String groupKey = getGroupKey(tpId, itemTenantKey);
@ -155,11 +154,9 @@ public class ThreadPoolController {
Map<String, String> activeMap =
leases.stream().map(each -> each.getHolder()).filter(each -> StringUtil.isNotBlank(each.getActive()))
.collect(Collectors.toMap(InstanceInfo::getIdentify, InstanceInfo::getActive));
Map<String, String> clientBasePathMap = leases.stream().map(each -> each.getHolder())
.filter(each -> StringUtil.isNotBlank(each.getClientBasePath()))
.collect(Collectors.toMap(InstanceInfo::getIdentify, InstanceInfo::getClientBasePath));
List<ThreadPoolInstanceInfo> returnThreadPool = Lists.newArrayList();
content.forEach((key, val) -> {
ThreadPoolInstanceInfo threadPoolInstanceInfo =
@ -170,7 +167,6 @@ public class ThreadPoolController {
threadPoolInstanceInfo.setClientBasePath(clientBasePathMap.get(key));
returnThreadPool.add(threadPoolInstanceInfo);
});
return Results.success(returnThreadPool);
}
@ -181,7 +177,6 @@ public class ThreadPoolController {
if (first == null) {
return Results.success(Lists.newArrayList());
}
List<ThreadPoolInstanceInfo> returnThreadPool = Lists.newArrayList();
leases.forEach(each -> {
InstanceInfo holder = each.getHolder();
@ -189,11 +184,8 @@ public class ThreadPoolController {
threadPoolInstanceInfo.setActive(holder.getActive());
threadPoolInstanceInfo.setClientAddress(holder.getCallBackUrl());
threadPoolInstanceInfo.setIdentify(holder.getIdentify());
returnThreadPool.add(threadPoolInstanceInfo);
});
return Results.success(returnThreadPool);
}
}

@ -92,5 +92,4 @@ public class UserController {
List<String> resultUserNames = userService.getUserLikeUsername(userName);
return Results.success(resultUserNames);
}
}

@ -31,23 +31,22 @@ import lombok.experimental.Accessors;
public class ChartInfo {
/**
*
* tenantCount
*/
private Integer tenantCount;
/**
*
* itemCount
*/
private Integer itemCount;
/**
* 线
* threadPoolCount
*/
private Integer threadPoolCount;
/**
* 线
* threadPoolInstanceCount
*/
private Integer threadPoolInstanceCount;
}

@ -53,5 +53,4 @@ public class LineChartInfo {
* fourList
*/
private List<Object> fourList;
}

@ -44,5 +44,4 @@ public class PieChartInfo {
* pieDataList
*/
private List<Map<String, Object>> pieDataList;
}

@ -56,7 +56,5 @@ public class RankingChart {
* inst
*/
private Integer inst;
}
}

@ -39,5 +39,4 @@ public class TenantChart {
* tenantCharts
*/
private List<Map<String, Object>> tenantCharts;
}

@ -48,5 +48,4 @@ public class ThreadPoolInstanceInfo extends ConfigAllInfo {
* active
*/
private String active;
}

@ -61,5 +61,4 @@ public interface DashboardService {
* @return
*/
RankingChart getRankingChart();
}

@ -17,16 +17,15 @@
package cn.hippo4j.console.service.impl;
import cn.hippo4j.common.enums.DelEnum;
import cn.hippo4j.common.model.InstanceInfo;
import cn.hippo4j.common.toolkit.GroupKey;
import cn.hippo4j.common.enums.DelEnum;
import cn.hippo4j.config.mapper.ConfigInfoMapper;
import cn.hippo4j.config.mapper.HisRunDataMapper;
import cn.hippo4j.config.mapper.ItemInfoMapper;
import cn.hippo4j.config.mapper.TenantInfoMapper;
import cn.hippo4j.config.model.*;
import cn.hippo4j.config.service.ConfigCacheService;
import cn.hippo4j.config.service.biz.HisRunDataService;
import cn.hippo4j.console.model.*;
import cn.hippo4j.console.service.DashboardService;
import cn.hippo4j.discovery.core.BaseInstanceRegistry;
@ -65,8 +64,6 @@ public class DashboardServiceImpl implements DashboardService {
private final ConfigInfoMapper configInfoMapper;
private final HisRunDataService hisRunDataService;
private final HisRunDataMapper hisRunDataMapper;
private final BaseInstanceRegistry baseInstanceRegistry;
@ -76,7 +73,6 @@ public class DashboardServiceImpl implements DashboardService {
Integer tenantCount = tenantInfoMapper.selectCount(Wrappers.lambdaQuery(TenantInfo.class).eq(TenantInfo::getDelFlag, DelEnum.NORMAL));
Integer itemCount = itemInfoMapper.selectCount(Wrappers.lambdaQuery(ItemInfo.class).eq(ItemInfo::getDelFlag, DelEnum.NORMAL));
Integer threadPoolCount = configInfoMapper.selectCount(Wrappers.lambdaQuery(ConfigAllInfo.class).eq(ConfigAllInfo::getDelFlag, DelEnum.NORMAL));
ChartInfo chartInfo = new ChartInfo();
chartInfo.setTenantCount(tenantCount)
.setItemCount(itemCount)
@ -89,14 +85,11 @@ public class DashboardServiceImpl implements DashboardService {
public LineChartInfo getLineChatInfo() {
Date currentDate = new Date();
DateTime startTime = DateUtil.offsetMinute(currentDate, -10);
List<HisRunDataMapper.ThreadPoolTaskRanking> threadPoolTaskRankings = hisRunDataMapper.queryThreadPoolMaxRanking(startTime.getTime(), currentDate.getTime());
List<Object> oneList = Lists.newArrayList();
List<Object> twoList = Lists.newArrayList();
List<Object> threeList = Lists.newArrayList();
List<Object> fourList = Lists.newArrayList();
ArrayList<List<Object>> lists = Lists.newArrayList(oneList, twoList, threeList, fourList);
for (int i = 0; i < threadPoolTaskRankings.size(); i++) {
List<Object> eachList = lists.get(i);
@ -106,7 +99,6 @@ public class DashboardServiceImpl implements DashboardService {
eachList.add(taskRanking.getMaxRejectCount());
eachList.add(taskRanking.getMaxCompletedTaskCount());
}
return new LineChartInfo(oneList, twoList, threeList, fourList);
}
@ -126,16 +118,13 @@ public class DashboardServiceImpl implements DashboardService {
Integer threadPoolCount = configInfoMapper.selectCount(threadPoolQueryWrapper);
tenantThreadPoolNum += threadPoolCount;
}
Dict dict = Dict.create().set("name", tenant.getTenantId()).set("value", tenantThreadPoolNum);
tenantChartList.add(dict);
}
List resultTenantChartList = tenantChartList.stream()
.sorted((one, two) -> (int) two.get("value") - (int) one.get("value"))
.limit(5)
.collect(Collectors.toList());
return new TenantChart(resultTenantChartList);
}
@ -143,7 +132,6 @@ public class DashboardServiceImpl implements DashboardService {
public PieChartInfo getPieChart() {
LambdaQueryWrapper<ItemInfo> itemQueryWrapper = Wrappers.lambdaQuery(ItemInfo.class).eq(ItemInfo::getDelFlag, DelEnum.NORMAL).select(ItemInfo::getItemId);
List<Object> itemNameList = itemInfoMapper.selectObjs(itemQueryWrapper);
List<Map<String, Object>> pieDataList = Lists.newArrayList();
for (Object each : itemNameList) {
LambdaQueryWrapper<ConfigAllInfo> threadPoolQueryWrapper = Wrappers.lambdaQuery(ConfigAllInfo.class)
@ -155,9 +143,7 @@ public class DashboardServiceImpl implements DashboardService {
pieDataList.add(dict);
}
}
pieDataList.sort((one, two) -> (int) two.get("value") - (int) one.get("value"));
List<String> resultItemIds = Lists.newArrayList();
List<Map<String, Object>> resultPieDataList = pieDataList.stream()
.limit(5)
@ -166,7 +152,6 @@ public class DashboardServiceImpl implements DashboardService {
return each;
})
.collect(Collectors.toList());
return new PieChartInfo(resultItemIds, resultPieDataList);
}
@ -174,7 +159,6 @@ public class DashboardServiceImpl implements DashboardService {
public RankingChart getRankingChart() {
Date currentDate = new Date();
DateTime tenTime = DateUtil.offsetMinute(currentDate, -10);
List<RankingChart.RankingChartInfo> resultList = Lists.newArrayList();
List<HisRunDataMapper.ThreadPoolTaskRanking> threadPoolTaskRankings = hisRunDataMapper.queryThreadPoolTaskSumRanking(tenTime.getTime(), currentDate.getTime());
threadPoolTaskRankings.forEach(each -> {
@ -191,14 +175,10 @@ public class DashboardServiceImpl implements DashboardService {
Map<String, CacheItem> content = ConfigCacheService.getContent(groupKey);
rankingChartInfo.setInst(content.keySet().size());
}
String keyTenant = GroupKey.getKeyTenant(each.getTenantId(), each.getItemId(), each.getTpId());
rankingChartInfo.setGroupKey(keyTenant);
resultList.add(rankingChartInfo);
});
return new RankingChart(resultList);
}
}

@ -39,5 +39,4 @@ public class RegistryConfiguration {
public void registryInit() {
baseInstanceRegistry.postInit();
}
}

@ -72,5 +72,4 @@ public class ApplicationController {
instanceRegistry.remove(instanceInfo);
return Results.success();
}
}

@ -110,13 +110,11 @@ public class BaseInstanceRegistry implements InstanceRegistry<InstanceInfo> {
public boolean renew(InstanceInfo.InstanceRenew instanceRenew) {
String appName = instanceRenew.getAppName();
String instanceId = instanceRenew.getInstanceId();
Map<String, Lease<InstanceInfo>> registryMap = registry.get(appName);
Lease<InstanceInfo> leaseToRenew;
if (registryMap == null || (leaseToRenew = registryMap.get(instanceId)) == null) {
return false;
}
leaseToRenew.renew();
return true;
}
@ -130,13 +128,11 @@ public class BaseInstanceRegistry implements InstanceRegistry<InstanceInfo> {
log.warn("Failed to remove unhealthy node, no application found :: {}", appName);
return;
}
Lease<InstanceInfo> remove = leaseMap.remove(instanceId);
if (remove == null) {
log.warn("Failed to remove unhealthy node, no instance found :: {}", instanceId);
return;
}
log.info("Remove unhealthy node, node ID :: {}", instanceId);
}
@ -153,7 +149,6 @@ public class BaseInstanceRegistry implements InstanceRegistry<InstanceInfo> {
}
}
}
for (Lease<InstanceInfo> expiredLease : expiredLeases) {
String appName = expiredLease.getHolder().getAppName();
String id = expiredLease.getHolder().getInstanceId();
@ -167,10 +162,8 @@ public class BaseInstanceRegistry implements InstanceRegistry<InstanceInfo> {
if (!CollectionUtils.isEmpty(registerMap)) {
registerMap.remove(id);
AbstractSubjectCenter.notify(AbstractSubjectCenter.SubjectType.CLEAR_CONFIG_CACHE, () -> identify);
log.info("Clean up unhealthy nodes. Node id :: {}", id);
}
return true;
}
@ -195,7 +188,6 @@ public class BaseInstanceRegistry implements InstanceRegistry<InstanceInfo> {
if (lastNanos == 0L) {
return 0L;
}
long elapsedMs = TimeUnit.NANOSECONDS.toMillis(currNanos - lastNanos);
long compensationTime = elapsedMs - EVICTION_INTERVAL_TIMER_IN_MS;
return compensationTime <= 0L ? 0L : compensationTime;
@ -221,5 +213,4 @@ public class BaseInstanceRegistry implements InstanceRegistry<InstanceInfo> {
scheduledExecutorService.scheduleWithFixedDelay(evictionTaskRef.get(),
EVICTION_INTERVAL_TIMER_IN_MS, EVICTION_INTERVAL_TIMER_IN_MS, TimeUnit.MILLISECONDS);
}
}

@ -42,7 +42,6 @@ public class ClientCloseHookRemoveNode implements ClientCloseHookExecute {
log.info(
"Remove Node, Execute client hook function. Req :: {}",
JSONUtil.toJSONString(req));
try {
InstanceInfo instanceInfo = new InstanceInfo();
instanceInfo.setAppName(req.getAppName()).setInstanceId(req.getInstanceId());
@ -51,5 +50,4 @@ public class ClientCloseHookRemoveNode implements ClientCloseHookExecute {
log.error("Failed to delete node hook.", ex);
}
}
}

@ -58,5 +58,4 @@ public interface InstanceRegistry<T> {
* @param info
*/
void remove(T info);
}

@ -113,5 +113,4 @@ public class Lease<T> {
public T getHolder() {
return holder;
}
}

@ -36,5 +36,4 @@ public class ServerApplication {
public static void main(String[] args) {
SpringApplication.run(ServerApplication.class, args);
}
}

@ -72,5 +72,4 @@ public class BaseSpringApplicationRunListener implements SpringApplicationRunLis
public int getOrder() {
return HIGHEST_PRECEDENCE;
}
}

@ -53,5 +53,4 @@ public interface Hippo4JApplicationListener {
* @param exception
*/
void failed(ConfigurableApplicationContext context, Throwable exception);
}

@ -54,7 +54,6 @@ public class StartingApplicationListener implements Hippo4JApplicationListener {
thread.setName("server.hippo4j-starting");
return thread;
});
scheduledExecutorService.scheduleWithFixedDelay(() -> {
if (starting) {
log.info("Hippo4J is starting...");
@ -66,9 +65,7 @@ public class StartingApplicationListener implements Hippo4JApplicationListener {
@Override
public void started(ConfigurableApplicationContext context) {
starting = false;
closeExecutor();
if (EnvUtil.getStandaloneMode()) {
log.info("Hippo4J started successfully...");
}
@ -77,10 +74,8 @@ public class StartingApplicationListener implements Hippo4JApplicationListener {
@Override
public void failed(ConfigurableApplicationContext context, Throwable exception) {
log.error("Startup errors : {}", exception);
closeExecutor();
context.close();
log.error("Hippo4J failed to start, please see {} for more details.",
Paths.get(EnvUtil.getHippo4JHome(), "logs/hippo4j.log"));
}
@ -90,5 +85,4 @@ public class StartingApplicationListener implements Hippo4JApplicationListener {
scheduledExecutorService.shutdownNow();
}
}
}

@ -18,18 +18,12 @@
package cn.hippo4j.tools.logrecord.annotation;
/**
* , .
* Log field, used to mark entity properties that need to be compared.
*
* @author chen.ma
* @date 2021/10/23 21:29
*/
public @interface LogField {
/**
*
*
* @return
*/
String name();
}

Loading…
Cancel
Save