Merge pull request #518 from mabaiwan/develop

hippo4j server add dynamic registration notification alarm
pull/536/head
小马哥 2 years ago committed by GitHub
commit 3c8564b9a8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -33,6 +33,15 @@ import lombok.NoArgsConstructor;
@AllArgsConstructor
public class DynamicThreadPoolRegisterWrapper {
// Hippo4j common ----------------------------------------------------------------------
/**
* Dynamic thread-pool register parameter
*/
private DynamicThreadPoolRegisterParameter dynamicThreadPoolRegisterParameter;
// Hippo4j server ----------------------------------------------------------------------
/**
* Tenant id
*/
@ -49,17 +58,14 @@ public class DynamicThreadPoolRegisterWrapper {
private Boolean updateIfExists = Boolean.TRUE;
/**
* Dynamic thread-pool register parameter
* Dynamic thread-pool server notify parameter
*/
private DynamicThreadPoolRegisterParameter dynamicThreadPoolRegisterParameter;
private DynamicThreadPoolRegisterServerNotifyParameter dynamicThreadPoolRegisterServerNotifyParameter;
// Hippo4j core ----------------------------------------------------------------------
/**
* Dynamic thread-pool core notify parameter
*/
private DynamicThreadPoolRegisterCoreNotifyParameter dynamicThreadPoolRegisterCoreNotifyParameter;
/**
* Dynamic thread-pool server notify parameter
*/
private DynamicThreadPoolRegisterServerNotifyParameter dynamicThreadPoolRegisterServerNotifyParameter;
}

@ -31,21 +31,11 @@ import lombok.NoArgsConstructor;
@AllArgsConstructor
public class DynamicThreadPoolRegisterServerNotifyParameter {
/**
* Thread-pool id
*/
private String threadPoolId;
/**
* Platform
*/
private String platform;
/**
* Config type
*/
private String type;
/**
* Secret key
*/

@ -18,6 +18,7 @@
package cn.hippo4j.config.model.biz.notify;
import lombok.Data;
import lombok.experimental.Accessors;
/**
* Notify req DTO.
@ -26,6 +27,7 @@ import lombok.Data;
* @date 2021/11/18 20:15
*/
@Data
@Accessors(chain = true)
public class NotifyReqDTO {
/**
@ -58,6 +60,11 @@ public class NotifyReqDTO {
*/
private String platform;
/**
* Type
*/
private String type;
/**
* Config type
*/

@ -60,6 +60,13 @@ public interface NotifyService {
*/
void update(NotifyReqDTO reqDTO);
/**
* Save or update.
*
* @param reqDTO
*/
void saveOrUpdate(NotifyReqDTO reqDTO);
/**
* Delete.
*

@ -21,6 +21,7 @@ import cn.hippo4j.common.config.ApplicationContextHolder;
import cn.hippo4j.common.enums.DelEnum;
import cn.hippo4j.common.model.register.DynamicThreadPoolRegisterParameter;
import cn.hippo4j.common.model.register.DynamicThreadPoolRegisterWrapper;
import cn.hippo4j.common.model.register.notify.DynamicThreadPoolRegisterServerNotifyParameter;
import cn.hippo4j.common.toolkit.*;
import cn.hippo4j.common.web.exception.ServiceException;
import cn.hippo4j.config.event.LocalDataChangeEvent;
@ -30,18 +31,17 @@ import cn.hippo4j.config.model.ConfigAllInfo;
import cn.hippo4j.config.model.ConfigInfoBase;
import cn.hippo4j.config.model.ConfigInstanceInfo;
import cn.hippo4j.config.model.LogRecordInfo;
import cn.hippo4j.config.model.biz.notify.NotifyReqDTO;
import cn.hippo4j.config.service.ConfigCacheService;
import cn.hippo4j.config.service.ConfigChangePublisher;
import cn.hippo4j.config.service.biz.ConfigService;
import cn.hippo4j.config.service.biz.ItemService;
import cn.hippo4j.config.service.biz.OperationLogService;
import cn.hippo4j.config.service.biz.TenantService;
import cn.hippo4j.config.service.biz.*;
import cn.hippo4j.config.toolkit.BeanUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.toolkit.SqlHelper;
import com.google.common.collect.Lists;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
@ -68,6 +68,8 @@ public class ConfigServiceImpl implements ConfigService {
private final OperationLogService operationLogService;
private final NotifyService notifyService;
@Override
public ConfigAllInfo findConfigAllInfo(String tpId, String itemId, String tenantId) {
LambdaQueryWrapper<ConfigAllInfo> wrapper = Wrappers.lambdaQuery(ConfigAllInfo.class)
@ -151,6 +153,28 @@ public class ConfigServiceImpl implements ConfigService {
ConfigServiceImpl configService = ApplicationContextHolder.getBean(this.getClass());
configService.updateConfigInfo(null, false, configAllInfo);
}
DynamicThreadPoolRegisterServerNotifyParameter serverNotifyParameter = registerWrapper.getDynamicThreadPoolRegisterServerNotifyParameter();
if (serverNotifyParameter != null) {
ArrayList<String> notifyTypes = Lists.newArrayList("CONFIG", "ALARM");
notifyTypes.forEach(each -> {
NotifyReqDTO notifyReqDTO = new NotifyReqDTO();
notifyReqDTO.setType(each)
.setEnable(1)
.setTenantId(registerWrapper.getTenantId())
.setItemId(registerWrapper.getItemId())
.setTpId(configAllInfo.getTpId())
.setPlatform(serverNotifyParameter.getPlatform())
.setReceives(serverNotifyParameter.getReceives())
.setSecretKey(serverNotifyParameter.getSecretKey());
if (Objects.equals(each, "ALARM")) {
notifyReqDTO.setInterval(serverNotifyParameter.getInterval());
notifyReqDTO.setAlarmType(true);
} else {
notifyReqDTO.setConfigType(true);
}
notifyService.saveOrUpdate(notifyReqDTO);
});
}
}
private ConfigAllInfo parseConfigAllInfo(DynamicThreadPoolRegisterWrapper registerWrapper) {

@ -119,6 +119,23 @@ public class NotifyServiceImpl implements NotifyService {
}
}
@Override
public void saveOrUpdate(NotifyReqDTO reqDTO) {
try {
existNotify(reqDTO.getType(), reqDTO);
save(reqDTO);
} catch (Exception ignored) {
LambdaQueryWrapper<NotifyInfo> queryWrapper = Wrappers.lambdaQuery(NotifyInfo.class)
.eq(NotifyInfo::getTenantId, reqDTO.getTenantId())
.eq(NotifyInfo::getItemId, reqDTO.getItemId())
.eq(NotifyInfo::getTpId, reqDTO.getTpId())
.eq(NotifyInfo::getPlatform, reqDTO.getPlatform())
.eq(NotifyInfo::getType, reqDTO.getType());
List<NotifyInfo> notifyInfos = notifyInfoMapper.selectList(queryWrapper);
notifyInfos.forEach(each -> update(reqDTO.setId(String.valueOf(each.getId()))));
}
}
@Override
public void delete(NotifyReqDTO reqDTO) {
LambdaUpdateWrapper<NotifyInfo> updateWrapper = Wrappers.lambdaUpdate(NotifyInfo.class)

@ -53,8 +53,7 @@ public class RegisterDynamicThreadPoolTest {
parameterInfo.setCapacityAlarm(90);
parameterInfo.setActiveAlarm(90);
parameterInfo.setAllowCoreThreadTimeOut(Boolean.TRUE);
// core 模式和 server 模式,各选其一即可
// Core mode and server mode, you can choose one of them.
DynamicThreadPoolRegisterCoreNotifyParameter coreNotifyParameter = DynamicThreadPoolRegisterCoreNotifyParameter.builder()
.activeAlarm(80)
.capacityAlarm(80)
@ -65,7 +64,6 @@ public class RegisterDynamicThreadPoolTest {
DynamicThreadPoolRegisterServerNotifyParameter serverNotifyParameter = DynamicThreadPoolRegisterServerNotifyParameter.builder()
.platform(NotifyPlatformEnum.WECHAT.name())
.secretKey("xxx")
.threadPoolId(threadPoolId)
.interval(5)
.receives("chen.ma")
.build();

Loading…
Cancel
Save