Apache Flink - custom java options are not recognized inside job

我是研究僧i 提交于 2019-12-05 03:09:47

The question is very much connected with the runtime architecture of Flink [1].

I understand you're running your job in a standalone cluster. Remember that the JobManager and the TaskManagers run in separate jvm instances. You have to consider where each block of code will be executed.

For instance, the code in transformations like map or filter is executed on the TaskManager. The Code in the main method of your entry class is executed in the command line tool flink, which of course does not have the system property set, as it spawns a temporary(-d) jvm just for the job submission.

If you submit your job through WebUI the code from your main method is executed on the JobManager so the property will be set then.

In general I would rather discourage passing the program arguments through the system properties as it is a bad practice.


Below you have a simple example:

I started:

  • a JobManager with env.java.opts:"-Ddy.props.path=jobmanager"
  • a TaskManager with env.java.opts:"-Ddy.props.path=taskmanager"

The code of my job looks following:

object Main {
  def main(args: Array[String]): Unit = {
    val env = StreamExecutionEnvironment.getExecutionEnvironment
    val stream = env.fromCollection(1 to 4)

    val prop = System.getProperty("dy.props.path")
    stream.map(_ => System.getProperty("dy.props.path") + "  mainArg: " + prop).print()

    env.execute("stream")
  }
}

When I submit the code through flink tool the output is as follows:

taskmanager  mainArg: null
taskmanager  mainArg: null
taskmanager  mainArg: null
taskmanager  mainArg: null

When it is submitted through the WebUI I get:

taskmanager  mainArg: jobmanager
taskmanager  mainArg: jobmanager
taskmanager  mainArg: jobmanager
taskmanager  mainArg: jobmanager
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!