Unverified Commit c7a7f2c4 authored by 高岩's avatar 高岩 Committed by GitHub

Fixed the problem that the global variable information of the data source could…

Fixed the problem that the global variable information of the data source could not be obtained in the K8s mode (#1197)
parent 43b74456
...@@ -96,6 +96,25 @@ public class DBUtil { ...@@ -96,6 +96,25 @@ public class DBUtil {
close(conn); close(conn);
return map; return map;
} }
/**
* 获取数据源的连接信息,作为全局变量
* @param sql 查询SQL,必须只有两列的结果,第一个为数据库名称,第二个为配置信息
* @param config 核心数据库配置
* */
public static String getDbSourceSQLStatement(String sql, DBConfig config) throws SQLException, IOException {
Connection conn = getConnection(config);
String sqlStatements = "";
try (
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery(sql)) {
while (rs.next()) {
sqlStatements = sqlStatements + rs.getString(1) + ":=" + rs.getString(2) + "\n;\n";
}
}
close(conn);
return sqlStatements;
}
public static List<Map<String, String>> getListByID(String sql, DBConfig config) throws SQLException, IOException { public static List<Map<String, String>> getListByID(String sql, DBConfig config) throws SQLException, IOException {
Connection conn = getConnection(config); Connection conn = getConnection(config);
......
...@@ -98,6 +98,18 @@ public class Submiter { ...@@ -98,6 +98,18 @@ public class Submiter {
return Arrays.asList(SqlUtil.getStatements(sql)); return Arrays.asList(SqlUtil.getStatements(sql));
} }
public static String getDbSourceSqlStatements(DBConfig dbConfig) {
String sql = "select name,flink_config from dlink_database where enabled = 1";
try {
return DBUtil.getDbSourceSQLStatement(sql, dbConfig);
} catch (IOException | SQLException e) {
logger.error("{} --> 获取 数据源信息异常,请检查数据库连接,连接信息为:{} ,异常信息为:{}", LocalDateTime.now(),
dbConfig.toString(), e.getMessage(), e);
}
return "";
}
public static void submit(Integer id, DBConfig dbConfig) { public static void submit(Integer id, DBConfig dbConfig) {
logger.info(LocalDateTime.now() + "开始提交作业 -- " + id); logger.info(LocalDateTime.now() + "开始提交作业 -- " + id);
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
...@@ -109,6 +121,9 @@ public class Submiter { ...@@ -109,6 +121,9 @@ public class Submiter {
} }
sb.append("\n"); sb.append("\n");
} }
// 添加数据源全局变量
sb.append(getDbSourceSqlStatements(dbConfig));
// 添加自定义全局变量信息
sb.append(getFlinkSQLStatement(id, dbConfig)); sb.append(getFlinkSQLStatement(id, dbConfig));
List<String> statements = Submiter.getStatements(sb.toString()); List<String> statements = Submiter.getStatements(sb.toString());
ExecutorSetting executorSetting = ExecutorSetting.build(taskConfig); ExecutorSetting executorSetting = ExecutorSetting.build(taskConfig);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment