是否可以使用 Google Dataproc 上的初始化脚本将作业提交到集群?

Is it possible to submit a job to a cluster using initization script on Google Dataproc?

我在 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 上执行此操作时,未提交作业...

谢谢!

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

我找到了一个方法。 在 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

考虑使用Dataproc Workflow,它是为多步骤的工作流程设计的,创建集群,提交作业,删除集群。它比init actions更好,因为它是Dataproc的第一个class特性,会有一个Dataproc job resource,你可以查看历史。