From 0f3eed9d00e6b688342c7885b0d2fc2528481ce0 Mon Sep 17 00:00:00 2001 From: Shiwen Cheng Date: Thu, 29 Apr 2021 16:17:01 +0800 Subject: [PATCH] [Fix-5386][Alert] Fix ERROR: relation t_ds_plugin_define does not exist (#5387) --- .../dolphinscheduler/alert/AlertServer.java | 23 +++++++++++++++---- .../alert/AlertServerTest.java | 7 ++---- .../dolphinscheduler/dao/PluginDao.java | 9 ++++++++ .../dao/mapper/PluginDefineMapper.java | 7 ++++++ .../dao/mapper/PluginDefineMapper.xml | 4 ++++ 5 files changed, 40 insertions(+), 10 deletions(-) diff --git a/dolphinscheduler-alert/src/main/java/org/apache/dolphinscheduler/alert/AlertServer.java b/dolphinscheduler-alert/src/main/java/org/apache/dolphinscheduler/alert/AlertServer.java index d0fb66af4b..f0ab241e19 100644 --- a/dolphinscheduler-alert/src/main/java/org/apache/dolphinscheduler/alert/AlertServer.java +++ b/dolphinscheduler-alert/src/main/java/org/apache/dolphinscheduler/alert/AlertServer.java @@ -30,6 +30,7 @@ import org.apache.dolphinscheduler.common.thread.Stopper; import org.apache.dolphinscheduler.common.utils.PropertyUtils; import org.apache.dolphinscheduler.dao.AlertDao; import org.apache.dolphinscheduler.dao.DaoFactory; +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; @@ -47,7 +48,14 @@ import com.google.common.collect.ImmutableList; * alert of start */ public class AlertServer { + private static final Logger logger = LoggerFactory.getLogger(AlertServer.class); + + /** + * Plugin Dao + */ + private PluginDao pluginDao = DaoFactory.getDaoInstance(PluginDao.class); + /** * Alert Dao */ @@ -55,8 +63,6 @@ public class AlertServer { private AlertSender alertSender; - private static AlertServer instance; - private AlertPluginManager alertPluginManager; private DolphinPluginManagerConfig alertPluginManagerConfig; @@ -78,13 +84,19 @@ public class AlertServer { public static final AlertServer getInstance() { return AlertServerHolder.INSTANCE; - } private AlertServer() { } + private void checkTable() { + if (!pluginDao.checkPluginDefineTableExist()) { + logger.error("Plugin Define Table t_ds_plugin_define Not Exist . Please Create it First !"); + System.exit(1); + } + } + private void initPlugin() { alertPluginManager = new AlertPluginManager(); alertPluginManagerConfig = new DolphinPluginManagerConfig(); @@ -101,7 +113,7 @@ public class AlertServer { try { alertPluginLoader.loadPlugins(); } catch (Exception e) { - throw new RuntimeException("load Alert Plugin Failed !", e); + throw new RuntimeException("Load Alert Plugin Failed !", e); } } @@ -128,7 +140,7 @@ public class AlertServer { Thread.currentThread().interrupt(); } if (alertPluginManager == null || alertPluginManager.getAlertChannelMap().size() == 0) { - logger.warn("No Alert Plugin . Can not send alert info. "); + logger.warn("No Alert Plugin . Cannot send alert info. "); } else { List alerts = alertDao.listWaitExecutionAlert(); alertSender = new AlertSender(alerts, alertDao, alertPluginManager); @@ -142,6 +154,7 @@ public class AlertServer { */ public void start() { PropertyUtils.loadPropertyFile(ALERT_PROPERTIES_PATH); + checkTable(); initPlugin(); initRemoteServer(); logger.info("alert server ready start "); diff --git a/dolphinscheduler-alert/src/test/java/org/apache/dolphinscheduler/alert/AlertServerTest.java b/dolphinscheduler-alert/src/test/java/org/apache/dolphinscheduler/alert/AlertServerTest.java index 662518b41e..1257856265 100644 --- a/dolphinscheduler-alert/src/test/java/org/apache/dolphinscheduler/alert/AlertServerTest.java +++ b/dolphinscheduler-alert/src/test/java/org/apache/dolphinscheduler/alert/AlertServerTest.java @@ -56,6 +56,7 @@ public class AlertServerTest { PluginDao pluginDao = PowerMockito.mock(PluginDao.class); PowerMockito.when(DaoFactory.getDaoInstance(PluginDao.class)).thenReturn(pluginDao); + PowerMockito.when(pluginDao.checkPluginDefineTableExist()).thenReturn(true); AlertChannel alertChannelMock = PowerMockito.mock(AlertChannel.class); @@ -80,15 +81,11 @@ public class AlertServerTest { AlertServer alertServer = AlertServer.getInstance(); Assert.assertNotNull(alertServer); - new Thread(() -> { - alertServer.start(); - }) - .start(); + new Thread(() -> alertServer.start()).start(); Thread.sleep(5 * Constants.ALERT_SCAN_INTERVAL); alertServer.stop(); - } } diff --git a/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/PluginDao.java b/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/PluginDao.java index 646307496b..b6aa9e5591 100644 --- a/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/PluginDao.java +++ b/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/PluginDao.java @@ -44,6 +44,15 @@ public class PluginDao extends AbstractBaseDao { pluginDefineMapper = ConnectionFactory.getInstance().getMapper(PluginDefineMapper.class); } + /** + * check plugin define table exist + * + * @return boolean + */ + public boolean checkPluginDefineTableExist() { + return pluginDefineMapper.checkTableExist() > 0; + } + /** * add pluginDefine * diff --git a/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/mapper/PluginDefineMapper.java b/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/mapper/PluginDefineMapper.java index e2d08b5222..1ce76707aa 100644 --- a/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/mapper/PluginDefineMapper.java +++ b/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/mapper/PluginDefineMapper.java @@ -27,6 +27,13 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper; public interface PluginDefineMapper extends BaseMapper { + /** + * check table exist + * + * @return boolean + */ + int checkTableExist(); + /** * query all plugin define * diff --git a/dolphinscheduler-dao/src/main/resources/org/apache/dolphinscheduler/dao/mapper/PluginDefineMapper.xml b/dolphinscheduler-dao/src/main/resources/org/apache/dolphinscheduler/dao/mapper/PluginDefineMapper.xml index 49abe7cb2d..0a105edcb0 100644 --- a/dolphinscheduler-dao/src/main/resources/org/apache/dolphinscheduler/dao/mapper/PluginDefineMapper.xml +++ b/dolphinscheduler-dao/src/main/resources/org/apache/dolphinscheduler/dao/mapper/PluginDefineMapper.xml @@ -18,6 +18,10 @@ + +