[Fix-5386][Alert] Fix ERROR: relation t_ds_plugin_define does not exist (#5387)
parent
d45b27ce2e
commit
0f3eed9d00
|
|
@ -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<Alert> 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 ");
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
*
|
||||
|
|
|
|||
|
|
@ -27,6 +27,13 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
|||
|
||||
public interface PluginDefineMapper extends BaseMapper<PluginDefine> {
|
||||
|
||||
/**
|
||||
* check table exist
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
int checkTableExist();
|
||||
|
||||
/**
|
||||
* query all plugin define
|
||||
*
|
||||
|
|
|
|||
|
|
@ -18,6 +18,10 @@
|
|||
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
|
||||
<mapper namespace="org.apache.dolphinscheduler.dao.mapper.PluginDefineMapper">
|
||||
<select id="checkTableExist" resultType="int">
|
||||
select count(*) from information_schema.TABLES where table_name = 't_ds_plugin_define'
|
||||
</select>
|
||||
|
||||
<select id="queryAllPluginDefineList" resultType="org.apache.dolphinscheduler.dao.entity.PluginDefine">
|
||||
select *
|
||||
from t_ds_plugin_define
|
||||
|
|
|
|||
Loading…
Reference in New Issue