2017-05-08 71 views

回答

0

有一对夫妇的可编程的方式来自动关闭集群:

  1. 调用REST api直接
  2. Use the gcloud CLI

无论是哪种,可以使用(所谓的)你的工作后( s)完成执行。

查看更多在这里: https://cloud.google.com/dataproc/docs/guides/manage-cluster#delete_a_cluster

+0

我想完全自动化这个任务。那么在这里,当工作完成执行时我们将如何得到通知?一旦我们获得了工作完成回调/通知,就可以使用REST API来删除集群。 –

+0

再次使用REST API。具体而言,作业资源上的'GET'并将其包装在轮询循环中 - https://cloud.google.com/dataproc/docs/reference/rest/v1/projects.regions.jobs/get。所以,提交> monitor> shutdown –

+0

好的。因此,外部脚本必须轮询作业状态,然后根据状态启动群集上的不同操作。使用自动关闭和缩放功能管理DataProc群集的任何工具/第三方软件?因为自动缩放也存在同样的问题。 DataFlow自行处理自动缩放。 –

1

你可以做到这一点与Scala代码: - 创建集群 - 运行工作 - 当作业结束删除集群

要做到这一点,你可以使用Scala工作未来。 如果你有很多工作可以并行运行:

val gcpJarBucket = "gs://test_dataproc/dataproc/Dataproc.jar" 
val jobs = Seq("package.class1","package.class2") 
val projectName: String = "automat-dataproc" 
val clusterName: String = "your-cluster-name" 

val timeout = 180 minute 

    // Working directory 
    implicit val wd = pwd 


    val future = Future { 
    println("Creating the spark cluster...") 
    % gcloud("dataproc", "clusters", "create", clusterName, "--subnet", "default", "--zone", "europe-west1-b", "--master-machine-type", "n1-standard-4", "--master-boot-disk-size", "50", "--num-workers", "3", "--worker-machine-type", "n1-standard-4", "--worker-boot-disk-size", "50", "--project", projectName) 
    println("Creating the spark cluster...DONE") 
    }.flatMap { _ => { 
    Future.sequence { 
     jobs.map { jobClass => 
     Future { 
      println(s"Launching the spark job from the class $jobClass...") 
      % gcloud("dataproc", "jobs", "submit", "spark", s"--cluster=$clusterName", s"--class=$jobClass", "--region=global", s"--jars=$gcpJarBucket") 
      println(s"Launching the spark job from the class $jobClass...DONE") 
     } 
     } 
    } 

    }} 

Try{ Await.ready(future, timeout) }.recover{ case exp => println(exp) } 
    % bash("-c", s"printf 'Y\n' | gcloud dataproc cl