![](/img/trans.png)
[英]how to pass custom job id via google dataproc cluster job for spark using dataproc client
[英]How to create a Dataproc cluster with time to live using Python SDK
我尝试使用 python SDK 创建一个生存时间为 1 天的 Dataproc 集群。 为此,Dataproc API 的 v1beta2 引入了LifecycleConfig object ,它是 ClusterConfig object 的子项。
我在传递给create_cluster
方法的 JSON 文件中使用了这个 object。 要设置特定的 TTL,我使用字段auto_delete_ttl
,其值为 86,400 秒(一天)。
Google Protocol Buffers 的文档非常具体地说明了如何在 JSON 文件中表示持续时间:Durations shall be represented as string with suffix s for seconds 并且应该有 0、3、6 或 9 小数秒:
但是,如果我使用这种格式传递持续时间,则会收到错误消息:
MergeFrom() 的参数必须是相同 class 的实例:预期的 google.protobuf.Duration 得到了 str
这就是我创建集群的方式:
from google.cloud import dataproc_v1beta2
project = "your_project_id"
region = "europe-west4"
cluster = "" #see below for cluster JSON file
client = dataproc_v1beta2.ClusterControllerClient(client_options={
'api_endpoint': '{}-dataproc.googleapis.com:443'.format(region)
})
# Create the cluster
operation = client.create_cluster(project, region, cluster)
变量 cluster 包含描述所需集群的 JSON object:
{
"cluster_name":"my_cluster",
"config":{
"config_bucket":"my_conf_bucket",
"gce_cluster_config":{
"zone_uri":"europe-west4-a",
"metadata":{
"PIP_PACKAGES":"google-cloud-storage google-cloud-bigquery"
},
"subnetwork_uri":"my subnet",
"service_account_scopes":[
"https://www.googleapis.com/auth/cloud-platform"
],
"tags":[
"some tags"
]
},
"master_config":{
"num_instances":1,
"machine_type_uri":"n1-highmem-4",
"disk_config":{
"boot_disk_type":"pd-standard",
"boot_disk_size_gb":200,
"num_local_ssds":0
},
"accelerators":[
]
},
"software_config":{
"image_version":"1.4-debian9",
"properties":{
"dataproc:dataproc.allow.zero.workers":"true",
"yarn:yarn.log-aggregation-enable":"true",
"dataproc:dataproc.logging.stackdriver.job.driver.enable":"true",
"dataproc:dataproc.logging.stackdriver.enable":"true",
"dataproc:jobs.file-backed-output.enable":"true"
},
"optional_components":[
]
},
"lifecycle_config":{
"auto_delete_ttl":"86400s"
},
"initialization_actions":[
{
"executable_file":"gs://some-init-script"
}
]
},
"project_id":"project_id"
}
我正在使用的 Package 版本:
我在这里做错了什么,这是错误的 package 版本的问题还是它甚至是一个错误?
当您以文本格式(即 json 等)构建 protobuf 时,您应该使用100s
格式作为持续时间类型,但是您使用的是 Python object 来构建 API 请求主体,这就是为什么您需要创建持续时间 object而不是字符串:
duration_message.FromSeconds(86400)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.