You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@dolphinscheduler.apache.org by GitBox <gi...@apache.org> on 2022/04/02 01:36:41 UTC

[GitHub] [dolphinscheduler] guoshupei commented on a change in pull request #9246: [Fix-9221] [alert-server] optimization and gracefully close

guoshupei commented on a change in pull request #9246:
URL: https://github.com/apache/dolphinscheduler/pull/9246#discussion_r840989920



##########
File path: dolphinscheduler-alert/dolphinscheduler-alert-server/src/main/java/org/apache/dolphinscheduler/alert/AlertPluginManager.java
##########
@@ -53,25 +52,22 @@
 public final class AlertPluginManager {
     private static final Logger logger = LoggerFactory.getLogger(AlertPluginManager.class);
 
-    private final PluginDao pluginDao;
+    @Autowired
+    private PluginDao pluginDao;
 
     private final Map<Integer, AlertChannel> channelKeyedById = new HashMap<>();
 
     private final PluginParams warningTypeParams = getWarningTypeParams();
 
-    public AlertPluginManager(PluginDao pluginDao) {
-        this.pluginDao = pluginDao;
-    }
-

Review comment:
       > This part is a different spring injection method, it is not recommended to modify.
   
   yes, I know, first, this is constructor injection, and has the same effect as @Autowired, both are byType, secondly, keep the style consistent, such as master/worker. What do you think?

##########
File path: dolphinscheduler-alert/dolphinscheduler-alert-server/src/main/java/org/apache/dolphinscheduler/alert/AlertSenderService.java
##########
@@ -17,43 +17,60 @@
 
 package org.apache.dolphinscheduler.alert;
 
-import org.apache.dolphinscheduler.alert.api.AlertChannel;
-import org.apache.dolphinscheduler.alert.api.AlertConstants;
-import org.apache.dolphinscheduler.alert.api.AlertData;
-import org.apache.dolphinscheduler.alert.api.AlertInfo;
-import org.apache.dolphinscheduler.alert.api.AlertResult;
+import org.apache.commons.collections.CollectionUtils;
+import org.apache.dolphinscheduler.alert.api.*;
+import org.apache.dolphinscheduler.common.Constants;
 import org.apache.dolphinscheduler.common.enums.AlertStatus;
 import org.apache.dolphinscheduler.common.enums.WarningType;
+import org.apache.dolphinscheduler.common.thread.Stopper;
 import org.apache.dolphinscheduler.common.utils.JSONUtils;
 import org.apache.dolphinscheduler.dao.AlertDao;
 import org.apache.dolphinscheduler.dao.entity.Alert;
 import org.apache.dolphinscheduler.dao.entity.AlertPluginInstance;
 import org.apache.dolphinscheduler.remote.command.alert.AlertSendResponseCommand;
 import org.apache.dolphinscheduler.remote.command.alert.AlertSendResponseResult;
-
-import org.apache.commons.collections.CollectionUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
 
 import java.util.ArrayList;
 import java.util.List;
 import java.util.Map;
 import java.util.Optional;
+import java.util.concurrent.TimeUnit;
 
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.springframework.stereotype.Component;
+@Service
+public final class AlertSenderService extends Thread {
+    private static final Logger logger = LoggerFactory.getLogger(AlertSenderService.class);
 
-@Component
-public final class AlertSender {
-    private static final Logger logger = LoggerFactory.getLogger(AlertSender.class);
+    @Autowired
+    private AlertDao alertDao;
 
-    private final AlertDao alertDao;
-    private final AlertPluginManager alertPluginManager;
+    @Autowired
+    private AlertPluginManager alertPluginManager;
 
-    public AlertSender(AlertDao alertDao, AlertPluginManager alertPluginManager) {
-        this.alertDao = alertDao;
-        this.alertPluginManager = alertPluginManager;

Review comment:
       same as previous answer

##########
File path: dolphinscheduler-alert/dolphinscheduler-alert-server/src/main/java/org/apache/dolphinscheduler/alert/AlertSenderService.java
##########
@@ -17,43 +17,60 @@
 
 package org.apache.dolphinscheduler.alert;
 
-import org.apache.dolphinscheduler.alert.api.AlertChannel;
-import org.apache.dolphinscheduler.alert.api.AlertConstants;
-import org.apache.dolphinscheduler.alert.api.AlertData;
-import org.apache.dolphinscheduler.alert.api.AlertInfo;
-import org.apache.dolphinscheduler.alert.api.AlertResult;
+import org.apache.commons.collections.CollectionUtils;
+import org.apache.dolphinscheduler.alert.api.*;

Review comment:
       okay, thanks

##########
File path: dolphinscheduler-alert/dolphinscheduler-alert-server/src/main/java/org/apache/dolphinscheduler/alert/AlertRequestProcessor.java
##########
@@ -36,11 +37,8 @@
 public final class AlertRequestProcessor implements NettyRequestProcessor {
     private static final Logger logger = LoggerFactory.getLogger(AlertRequestProcessor.class);
 
-    private final AlertSender alertSender;
-
-    public AlertRequestProcessor(AlertSender alertSender) {
-        this.alertSender = alertSender;
-    }

Review comment:
       same as previous answer

##########
File path: dolphinscheduler-alert/dolphinscheduler-alert-server/src/main/java/org/apache/dolphinscheduler/alert/AlertServer.java
##########
@@ -17,73 +17,104 @@
 
 package org.apache.dolphinscheduler.alert;
 
+import org.apache.dolphinscheduler.common.Constants;
+import org.apache.dolphinscheduler.common.IStoppable;
 import org.apache.dolphinscheduler.common.thread.Stopper;
-import org.apache.dolphinscheduler.dao.AlertDao;
 import org.apache.dolphinscheduler.dao.PluginDao;
-import org.apache.dolphinscheduler.dao.entity.Alert;
 import org.apache.dolphinscheduler.remote.NettyRemotingServer;
 import org.apache.dolphinscheduler.remote.command.CommandType;
 import org.apache.dolphinscheduler.remote.config.NettyServerConfig;
-
-import java.io.Closeable;
-import java.util.List;
-import java.util.concurrent.Executors;
-import java.util.concurrent.TimeUnit;
-
-import javax.annotation.PreDestroy;
-
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.boot.SpringApplication;
+import org.springframework.boot.WebApplicationType;
 import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.boot.builder.SpringApplicationBuilder;
 import org.springframework.boot.context.event.ApplicationReadyEvent;
 import org.springframework.context.annotation.ComponentScan;
 import org.springframework.context.event.EventListener;
 
+import javax.annotation.PostConstruct;
+
 @SpringBootApplication
 @ComponentScan("org.apache.dolphinscheduler")
-public class AlertServer implements Closeable {
+public class AlertServer implements IStoppable {

Review comment:
       yes, you are right. The action of interface of `IStoppable`  is to stop by external trigger. such as `RegistryClient`, we can refer to master or worker. At present, `AlertServer` is  not distributed, and stop is not be used, but I think it should be reserved for distributed considerations.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@dolphinscheduler.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org