目录
1. flink-conf.yaml和flink命令自定义参数解析
1.1 上文回顾
上篇,我们讲解了EnvironmentInformation.logEnvironmentInfo函数。主要是log4j2日志框架如何绑定到Flink、log4j2配置文件和日志路径的定义
这篇我们来讲解Flink的flink-conf.yaml和flink命令自定义参数解析
1.2 获取Flink的conf目录路径
在flink-clients/src/org.apache.flink.client.cli.CliFrontend类的main方法中,定义了获取Flink的conf目录路径
/** Submits the job based on the arguments. */
public static void main(final String[] args) {
EnvironmentInformation.logEnvironmentInfo(LOG, "Command Line Client", args);
// 1. find the configuration directory
final String configurationDirectory = getConfigurationDirectoryFromEnv();
// 2. load the global configuration
final Configuration configuration =
GlobalConfiguration.loadConfiguration(configurationDirectory);
......省略部分......
}
这里调用了当前类CliFrontend的getConfigurationDirectoryFromEnv函数,函数实现具体如下:
// --------------------------------------------------------------------------------------------
// Miscellaneous Utilities
// --------------------------------------------------------------------------------------------
public static String getConfigurationDirectoryFromEnv() {
String location = System.getenv(ConfigConstants.ENV_FLINK_CONF_DIR);
if (location != null) {
if (new File(location).exists()) {
return location;
} else {
throw new RuntimeException(
"The configuration directory '"
+ location
+ "', specified in the '"
+ ConfigConstants.ENV_FLINK_CONF_DIR
+ "' environment variable, does not exist.");
}
} else if (new File(CONFIG_DIRECTORY_FALLBACK_1).exists()) {
location = CONFIG_DIRECTORY_FALLBACK_1;
} else if (new File(CONFIG_DIRECTORY_FALLBACK_2).exists()) {
location = CONFIG_DIRECTORY_FALLBACK_2;
} else {
throw new RuntimeException(
"The configuration directory was not specified. "
+ "Please specify the directory containing the configuration file through the '"
+ ConfigConstants.ENV_FLINK_CONF_DIR
+ "' environment variable.");
}
return location;
}
我们前面执行flink脚本时,调用了config.sh脚本,里面执行了export FLINK_CONF_DIR命令设置了flink的conf目录变量。这里再通过System.getenv进行flink conf目录路径的获取
1.3 加载flink-conf.yaml配置文件
在flink-clients/src/org.apache.flink.client.cli.CliFrontend类的main方法中,定义了加载flink-conf.yaml配置文件
/** Submits the job based on the arguments. *

本文深入解析Apache Flink的配置文件flink-conf.yaml,详细介绍了如何获取配置目录路径,加载配置文件,以及Flink命令行客户端的加载过程。主要内容包括:获取conf目录,加载全局配置,解析flink-conf.yaml,最后添加GenericCLI、FlinkYarnSessionCLI和DefaultCLI三种命令行客户端。文章还探讨了不同客户端的激活条件和功能。
1477

被折叠的 条评论
为什么被折叠?



