hippo4j alarm notification initialization (#523)

* Migration code package location

* Add condition to update if notification exists

* hippo4j alarm notification initialization
pull/536/head
小马哥 2 years ago committed by GitHub
parent 2d508c0dd2
commit bbe6d5ddaa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -33,6 +33,7 @@ import cn.hippo4j.core.toolkit.inet.InetUtils;
import cn.hippo4j.message.api.NotifyConfigBuilder; import cn.hippo4j.message.api.NotifyConfigBuilder;
import cn.hippo4j.message.config.MessageConfiguration; import cn.hippo4j.message.config.MessageConfiguration;
import cn.hippo4j.message.service.AlarmControlHandler; import cn.hippo4j.message.service.AlarmControlHandler;
import cn.hippo4j.message.service.Hippo4jBaseSendMessageService;
import cn.hippo4j.message.service.Hippo4jSendMessageService; import cn.hippo4j.message.service.Hippo4jSendMessageService;
import cn.hippo4j.springboot.starter.controller.ThreadPoolAdapterController; import cn.hippo4j.springboot.starter.controller.ThreadPoolAdapterController;
import cn.hippo4j.springboot.starter.controller.WebThreadPoolController; import cn.hippo4j.springboot.starter.controller.WebThreadPoolController;
@ -101,8 +102,10 @@ public class DynamicThreadPoolAutoConfiguration {
public DynamicThreadPoolService dynamicThreadPoolConfigService(HttpAgent httpAgent, public DynamicThreadPoolService dynamicThreadPoolConfigService(HttpAgent httpAgent,
ClientWorker clientWorker, ClientWorker clientWorker,
ServerHealthCheck serverHealthCheck, ServerHealthCheck serverHealthCheck,
ServerNotifyConfigBuilder notifyConfigBuilder,
Hippo4jBaseSendMessageService hippo4jBaseSendMessageService,
DynamicThreadPoolSubscribeConfig dynamicThreadPoolSubscribeConfig) { DynamicThreadPoolSubscribeConfig dynamicThreadPoolSubscribeConfig) {
return new DynamicThreadPoolConfigService(httpAgent, clientWorker, properties, dynamicThreadPoolSubscribeConfig); return new DynamicThreadPoolConfigService(httpAgent, clientWorker, properties, notifyConfigBuilder, hippo4jBaseSendMessageService, dynamicThreadPoolSubscribeConfig);
} }
@Bean @Bean

@ -55,12 +55,16 @@ public class ServerNotifyConfigBuilder implements NotifyConfigBuilder {
@Override @Override
public Map<String, List<NotifyConfigDTO>> buildNotify() { public Map<String, List<NotifyConfigDTO>> buildNotify() {
Map<String, List<NotifyConfigDTO>> resultMap = Maps.newHashMap();
List<String> threadPoolIds = GlobalThreadPoolManage.listThreadPoolId(); List<String> threadPoolIds = GlobalThreadPoolManage.listThreadPoolId();
if (CollUtil.isEmpty(threadPoolIds)) { if (CollUtil.isEmpty(threadPoolIds)) {
log.warn("The client does not have a dynamic thread pool instance configured."); log.warn("The client does not have a dynamic thread pool instance configured.");
return resultMap; return Maps.newHashMap();
}
return getAndInitNotify(threadPoolIds);
} }
public Map<String, List<NotifyConfigDTO>> getAndInitNotify(List<String> threadPoolIds) {
Map<String, List<NotifyConfigDTO>> resultMap = Maps.newHashMap();
List<String> groupKeys = Lists.newArrayList(); List<String> groupKeys = Lists.newArrayList();
threadPoolIds.forEach(each -> { threadPoolIds.forEach(each -> {
String groupKey = GroupKey.getKeyTenant(each, properties.getItemId(), properties.getNamespace()); String groupKey = GroupKey.getKeyTenant(each, properties.getItemId(), properties.getNamespace());

@ -29,16 +29,23 @@ import cn.hippo4j.core.executor.DynamicThreadPoolWrapper;
import cn.hippo4j.core.executor.manage.GlobalNotifyAlarmManage; import cn.hippo4j.core.executor.manage.GlobalNotifyAlarmManage;
import cn.hippo4j.core.executor.manage.GlobalThreadPoolManage; import cn.hippo4j.core.executor.manage.GlobalThreadPoolManage;
import cn.hippo4j.core.executor.support.service.AbstractDynamicThreadPoolService; import cn.hippo4j.core.executor.support.service.AbstractDynamicThreadPoolService;
import cn.hippo4j.message.dto.NotifyConfigDTO;
import cn.hippo4j.message.service.Hippo4jBaseSendMessageService;
import cn.hippo4j.message.service.ThreadPoolNotifyAlarm; import cn.hippo4j.message.service.ThreadPoolNotifyAlarm;
import cn.hippo4j.springboot.starter.config.BootstrapProperties; import cn.hippo4j.springboot.starter.config.BootstrapProperties;
import cn.hippo4j.springboot.starter.core.ClientWorker; import cn.hippo4j.springboot.starter.core.ClientWorker;
import cn.hippo4j.springboot.starter.core.DynamicThreadPoolSubscribeConfig; import cn.hippo4j.springboot.starter.core.DynamicThreadPoolSubscribeConfig;
import cn.hippo4j.springboot.starter.event.ApplicationCompleteEvent; import cn.hippo4j.springboot.starter.event.ApplicationCompleteEvent;
import cn.hippo4j.springboot.starter.notify.ServerNotifyConfigBuilder;
import cn.hippo4j.springboot.starter.remote.HttpAgent;
import com.google.common.collect.Lists;
import cn.hippo4j.springboot.starter.remote.HttpAgent; import cn.hippo4j.springboot.starter.remote.HttpAgent;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.context.ApplicationListener; import org.springframework.context.ApplicationListener;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ThreadPoolExecutor; import java.util.concurrent.ThreadPoolExecutor;
import static cn.hippo4j.common.constant.Constants.REGISTER_DYNAMIC_THREAD_POOL_PATH; import static cn.hippo4j.common.constant.Constants.REGISTER_DYNAMIC_THREAD_POOL_PATH;
@ -56,6 +63,10 @@ public class DynamicThreadPoolConfigService extends AbstractDynamicThreadPoolSer
private final BootstrapProperties properties; private final BootstrapProperties properties;
private final ServerNotifyConfigBuilder notifyConfigBuilder;
private final Hippo4jBaseSendMessageService hippo4jBaseSendMessageService;
private final DynamicThreadPoolSubscribeConfig dynamicThreadPoolSubscribeConfig; private final DynamicThreadPoolSubscribeConfig dynamicThreadPoolSubscribeConfig;
@Override @Override
@ -106,6 +117,8 @@ public class DynamicThreadPoolConfigService extends AbstractDynamicThreadPoolSer
registerParameter.getActiveAlarm(), registerParameter.getActiveAlarm(),
registerParameter.getCapacityAlarm()); registerParameter.getCapacityAlarm());
GlobalNotifyAlarmManage.put(registerParameter.getThreadPoolId(), threadPoolNotifyAlarm); GlobalNotifyAlarmManage.put(registerParameter.getThreadPoolId(), threadPoolNotifyAlarm);
Map<String, List<NotifyConfigDTO>> builderNotify = notifyConfigBuilder.getAndInitNotify(Lists.newArrayList(registerParameter.getThreadPoolId()));
hippo4jBaseSendMessageService.putPlatform(builderNotify);
} }
private void checkThreadPoolParameter(DynamicThreadPoolRegisterParameter registerParameter) { private void checkThreadPoolParameter(DynamicThreadPoolRegisterParameter registerParameter) {

Loading…
Cancel
Save