【问题标题】:Is it possible to submit a job to a cluster using initization script on Google Dataproc?是否可以使用 Google Dataproc 上的初始化脚本向集群提交作业?
【发布时间】:2021-09-08 11:29:41
【问题描述】:

我在 1 个集群上使用 Dataproc 和 1 个作业。

我想在集群创建后立即开始我的工作。我发现实现此目的的最佳方法是使用如下初始化脚本提交作业。

function submit_job() {
  echo "Submitting job..."
  gcloud dataproc jobs submit pyspark ...
}
export -f submit_job

function check_running() {
  echo "checking..."
  gcloud dataproc clusters list --region='asia-northeast1' --filter='clusterName = {{ cluster_name }}' |
  tail -n 1 |
  while read name platform worker_count preemptive_worker_count status others
  do
    if [ "$status" = "RUNNING" ]; then
      return 0
    fi
  done
}
export -f check_running

function after_initialization() {
  local role
  role=$(/usr/share/google/get_metadata_value attributes/dataproc-role)
  if [[ "${role}" == 'Master' ]]; then
    echo "monitoring the cluster..."
    while true; do
      if check_running; then
        submit_job
        break
      fi
      sleep 5
    done
  fi
}
export -f after_initialization

echo "start monitoring..."
bash -c after_initialization & disown -h

有可能吗?当我在 Dataproc 上运行此程序时,未提交作业...

谢谢!

【问题讨论】:

    标签: google-cloud-dataproc dataproc


    【解决方案1】:

    考虑使用Dataproc Workflow,它是为多步骤的工作流设计的,创建集群,提交作业,删除集群。它比 init actions 好,因为它是 Dataproc 的一流功能,会有一个 Dataproc 作业资源,并且可以查看历史记录。

    【讨论】:

    • 感谢您的建议!正如您所建议的,我发现使用 dataproc 工作流而不是初始化操作更好。
    【解决方案2】:

    请考虑使用云composer - 然后您可以编写一个脚本来创建集群、运行作业并终止集群。

    【讨论】:

    • 非常感谢您的回复,大卫。其实我不想用composer,因为不划算。
    【解决方案3】:

    我找到了办法。 在 GCS 上放置一个名为 await_cluster_and_run_command.sh 的 shell 脚本。然后,将以下代码添加到初始化脚本中。

    gsutil cp gs://...../await_cluster_and_run_command.sh /usr/local/bin/
    chmod 750 /usr/local/bin/await_cluster_and_run_command.sh
    nohup /usr/local/bin/await_cluster_and_run_command.sh &>>/var/log/master-post-init.log &
    

    参考:https://github.com/GoogleCloudDataproc/initialization-actions/blob/master/post-init/master-post-init.sh

    【讨论】:

    猜你喜欢
    • 2017-02-16
    • 2016-08-15
    • 1970-01-01
    • 2020-12-07
    • 1970-01-01
    • 2017-12-23
    • 2020-08-23
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多