Unverified Commit 50b46aad authored by Zzm0809's avatar Zzm0809 Committed by GitHub

[Fix] Fix unrecognized global variables defined by registry in application mode (#3266)

parent cfb99b61
......@@ -21,6 +21,7 @@ package org.dinky.app.db;
import org.dinky.app.model.SysConfig;
import org.dinky.data.app.AppDatabase;
import org.dinky.data.app.AppGlobalVariable;
import org.dinky.data.app.AppParamConfig;
import org.dinky.data.app.AppTask;
......@@ -28,6 +29,7 @@ import java.sql.SQLException;
import java.util.List;
import cn.hutool.core.text.StrFormatter;
import cn.hutool.core.util.StrUtil;
import cn.hutool.db.Db;
import cn.hutool.db.Entity;
import cn.hutool.db.ds.simple.SimpleDataSource;
......@@ -61,9 +63,31 @@ public class DBUtil {
Entity option = Entity.create("dinky_database").set("enabled", true);
List<AppDatabase> entities = db.find(option, AppDatabase.class);
for (AppDatabase entity : entities) {
// Filter out items with empty FlinkConfiguration, as this item is optional in the front-end form and does
// not need to be generated when it is empty
if (StrUtil.isNotBlank(entity.getFlinkConfig())) {
sb.append(entity.getName())
.append(":=")
.append(entity.getFlinkConfig())
.append("\n;\n");
}
}
return sb.toString();
}
/**
* Get the global variables statement获取全局变量
* @return the global variables statement
* @throws SQLException if a database access error occurs
*/
public static String getGlobalVariablesStatement() throws SQLException {
StringBuilder sb = new StringBuilder();
Entity option = Entity.create("dinky_fragment").set("enabled", true);
List<AppGlobalVariable> entities = db.find(option, AppGlobalVariable.class);
for (AppGlobalVariable entity : entities) {
sb.append(entity.getName())
.append(":=")
.append(entity.getFlinkConfig())
.append(entity.getFragmentValue())
.append("\n;\n");
}
return sb.toString();
......
......@@ -161,8 +161,11 @@ public class Submitter {
}
// build Database golbal varibals
if (appTask.getFragment()) {
log.info("Global env is enable, load database flink config env.");
log.info("Global env is enable, load database flink config env and global variables.");
// append database flink config env
sb.append(DBUtil.getDbSourceSQLStatement()).append("\n");
// append global variables
sb.append(DBUtil.getGlobalVariablesStatement()).append("\n");
}
sb.append(appTask.getStatement());
return sb.toString();
......
/*
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package org.dinky.data.app;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
@Data
public class AppGlobalVariable {
@ApiModelProperty(value = "ID", required = true, dataType = "Integer", example = "1", notes = "Primary Key")
private Integer id;
@ApiModelProperty(value = "Name", required = true, dataType = "String", example = "Name")
private String name;
@ApiModelProperty(value = "flinkConfig", dataType = "String", example = "flinkConfig")
private String fragmentValue;
}
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