Standalone cluster模式下怎么生成一个DriverDescription类型的消息

Standalone cluster模式下怎么生成一个DriverDescription类型的消息

这篇文章主要讲解了“Standalone cluster模式下怎么生成一个DriverDescription类型的消息”,文中的讲解内容简单清晰,易于学习与理解,下面请大家跟着小编的思路慢慢深入,一起来研究和学习“Standalone cluster模式下怎么生成一个DriverDescription类型的消息”吧!

先看看代码,这个类代码比较短,目录是deploy/rest/下。

private[spark] class RestSubmissionClientApp extends SparkApplication {
  /** Submits a request to run the application and return the response. Visible for testing. */
  def run(
      appResource: String,
      mainClass: String,
      appArgs: Array[String],
      conf: SparkConf,
      env: Map[String, String] = Map()): SubmitRestProtocolResponse = {
    val master = conf.getOption("spark.master").getOrElse {
      throw new IllegalArgumentException("'spark.master' must be set.")
    }
    val sparkProperties = conf.getAll.toMap
    val client = new RestSubmissionClient(master)
    val submitRequest = client.constructSubmitRequest(
      appResource, mainClass, appArgs, sparkProperties, env)
    client.createSubmission(submitRequest)
  }

  override def start(args: Array[String], conf: SparkConf): Unit = {
    if (args.length < 2) {
      sys.error("Usage: RestSubmissionClient [app resource] [main class] [app args*]")
      sys.exit(1)
    }
    val appResource = args(0)
    val mainClass = args(1)
    val appArgs = args.slice(2, args.length)
    val env = RestSubmissionClient.filterSystemEnvironment(sys.env)
    run(appResource, mainClass, appArgs, conf, env)
  }
}

创建一个RestSubmissionClient的client,然后将消息提交给client,消息的格式为:

( appResource, mainClass, appArgs, sparkProperties, env)

client.createSubmission(submitRequest)

client.createSubmission命令做哪些事呢?他就是提交消息给服务端,真实的处理者是服务端,是RestSubmissionServer类或者它的子类。对于独立集群来说,就是StandaloneRestServer来处理的,我们就只看submit命令的处理逻辑就可以了。

相关的函数有两个:

私有方法buildDriverDescription和重写接口方法handleSubmit

handleSubmit里调用了前一个方法,最关键的代码是两行:

val driverDescription = buildDriverDescription(submitRequest)
val response = masterEndpoint.askSync[DeployMessages.SubmitDriverResponse](
          DeployMessages.RequestSubmitDriver(driverDescription))

生成一个DriverDescription类型的消息,然后给Master发送RequestSubmitDriver消息,让Master来调度执行我们的spark程序,就是这里的driver。

接下来,就进入了Master的处理流程了。

   

感谢各位的阅读,以上就是“Standalone cluster模式下怎么生成一个DriverDescription类型的消息”的内容了,经过本文的学习后,相信大家对Standalone cluster模式下怎么生成一个DriverDescription类型的消息这一问题有了更深刻的体会,具体使用情况还需要大家实践验证。这里是亿速云,小编将为大家推送更多相关知识点的文章,欢迎关注!