From 128ede3ee9ddea5770517ce627f259e6a492fcbc Mon Sep 17 00:00:00 2001 From: wind Date: Tue, 25 Jan 2022 18:10:02 +0800 Subject: [PATCH] Fix start standalone fail because db not init yet (#8191) --- .../apache/dolphinscheduler/alert/AlertPluginManager.java | 6 ++++-- .../java/org/apache/dolphinscheduler/alert/AlertServer.java | 6 ++++-- .../dolphinscheduler/alert/AlertPluginManagerTest.java | 2 +- .../org/apache/dolphinscheduler/alert/AlertServerTest.java | 2 +- 4 files changed, 10 insertions(+), 6 deletions(-) diff --git a/dolphinscheduler-alert/dolphinscheduler-alert-server/src/main/java/org/apache/dolphinscheduler/alert/AlertPluginManager.java b/dolphinscheduler-alert/dolphinscheduler-alert-server/src/main/java/org/apache/dolphinscheduler/alert/AlertPluginManager.java index 6107cf6e0d..682a4961d7 100644 --- a/dolphinscheduler-alert/dolphinscheduler-alert-server/src/main/java/org/apache/dolphinscheduler/alert/AlertPluginManager.java +++ b/dolphinscheduler-alert/dolphinscheduler-alert-server/src/main/java/org/apache/dolphinscheduler/alert/AlertPluginManager.java @@ -39,6 +39,8 @@ import javax.annotation.PostConstruct; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.springframework.boot.context.event.ApplicationReadyEvent; +import org.springframework.context.event.EventListener; import org.springframework.stereotype.Component; @Component @@ -53,8 +55,8 @@ public final class AlertPluginManager { this.pluginDao = pluginDao; } - @PostConstruct - public void installPlugin() { + @EventListener + public void installPlugin(ApplicationReadyEvent readyEvent) { final Set names = new HashSet<>(); ServiceLoader.load(AlertChannelFactory.class).forEach(factory -> { diff --git a/dolphinscheduler-alert/dolphinscheduler-alert-server/src/main/java/org/apache/dolphinscheduler/alert/AlertServer.java b/dolphinscheduler-alert/dolphinscheduler-alert-server/src/main/java/org/apache/dolphinscheduler/alert/AlertServer.java index 6304a4c6b3..f8324ac2ac 100644 --- a/dolphinscheduler-alert/dolphinscheduler-alert-server/src/main/java/org/apache/dolphinscheduler/alert/AlertServer.java +++ b/dolphinscheduler-alert/dolphinscheduler-alert-server/src/main/java/org/apache/dolphinscheduler/alert/AlertServer.java @@ -38,7 +38,9 @@ import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.context.event.ApplicationReadyEvent; import org.springframework.context.annotation.ComponentScan; +import org.springframework.context.event.EventListener; @SpringBootApplication @ComponentScan("org.apache.dolphinscheduler") @@ -68,8 +70,8 @@ public class AlertServer implements Closeable { SpringApplication.run(AlertServer.class, args); } - @PostConstruct - public void start() { + @EventListener + public void start(ApplicationReadyEvent readyEvent) { logger.info("Starting Alert server"); checkTable(); diff --git a/dolphinscheduler-alert/dolphinscheduler-alert-server/src/test/java/org/apache/dolphinscheduler/alert/AlertPluginManagerTest.java b/dolphinscheduler-alert/dolphinscheduler-alert-server/src/test/java/org/apache/dolphinscheduler/alert/AlertPluginManagerTest.java index f7e7e56f94..912c959c84 100644 --- a/dolphinscheduler-alert/dolphinscheduler-alert-server/src/test/java/org/apache/dolphinscheduler/alert/AlertPluginManagerTest.java +++ b/dolphinscheduler-alert/dolphinscheduler-alert-server/src/test/java/org/apache/dolphinscheduler/alert/AlertPluginManagerTest.java @@ -41,7 +41,7 @@ public class AlertPluginManagerTest extends TestCase { public void testAlertPluginManager() { Mockito.when(pluginDao.addOrUpdatePluginDefine(Mockito.any(PluginDefine.class))).thenReturn(0); - alertPluginManager.installPlugin(); + alertPluginManager.installPlugin(null); Assert.assertEquals(1, alertPluginManager.size()); diff --git a/dolphinscheduler-alert/dolphinscheduler-alert-server/src/test/java/org/apache/dolphinscheduler/alert/AlertServerTest.java b/dolphinscheduler-alert/dolphinscheduler-alert-server/src/test/java/org/apache/dolphinscheduler/alert/AlertServerTest.java index bd5396a429..911b912d76 100644 --- a/dolphinscheduler-alert/dolphinscheduler-alert-server/src/test/java/org/apache/dolphinscheduler/alert/AlertServerTest.java +++ b/dolphinscheduler-alert/dolphinscheduler-alert-server/src/test/java/org/apache/dolphinscheduler/alert/AlertServerTest.java @@ -49,7 +49,7 @@ public class AlertServerTest extends TestCase { Mockito.when(alertConfig.getPort()).thenReturn(50053); - alertServer.start(); + alertServer.start(null); NettyRemotingServer nettyRemotingServer = Whitebox.getInternalState(alertServer, "server");