如何访问Dataproc集群元数据?

huangapple go评论74阅读模式
英文:

how to access Dataproc cluster metadata?

问题

在创建集群后,我试图获取我的附加组件的URL地址(不使用GCP仪表板)。我正在使用Dataproc Python API,具体来说是get_cluster()函数。

该函数返回了大量数据,但我无法找到Jupyter网关的URL或其他元数据。

from google.cloud import dataproc_v1

project_id, cluster_name = '', ''
region = 'europe-west4'

client = dataproc_v1.ClusterControllerClient(
                       client_options={
                            'api_endpoint': '{}-dataproc.googleapis.com:443'.format(region)
                        }
                    )

response = client.get_cluster(project_id, region, cluster_name)
print(response)

是否有人有解决方案?[1]: https://googleapis.dev/python/dataproc/latest/gapic/v1/api.html

英文:

After the creation of a cluster, I'm trying to retrieve the URL address of my additional components (without using the GCP Dashboard). I am using de [Dataproc python API][1] and more specifically the get_cluster() function.

A lot of data is returned by the function but I cannot manage to find the Jupyter gateway URL or other metadata.

from google.cloud import dataproc_v1

project_id, cluster_name = '', ''
region = 'europe-west4'

client = dataproc_v1.ClusterControllerClient(
                       client_options={
                            'api_endpoint': '{}-dataproc.googleapis.com:443'.format(region)
                        }
                    )


response = client.get_cluster(project_id, region, cluster_name)
print(response)

Does anyone as a solution to this?
[1]: https://googleapis.dev/python/dataproc/latest/gapic/v1/api.html

答案1

得分: 4

If you have followed this doc to setup Jupyter access by enabling Component Gateway, then you can access the Web Interfaces as described here. The trick is that this is included in the API response for the v1beta2 version.

Changes needed in the code are minimal (no additional requirements apart from google-cloud-dataproc library). Just replace dataproc_v1 for dataproc_v1beta2 and access the endpoints with response.config.endpoint_config:

from google.cloud import dataproc_v1beta2

project_id, cluster_name = '', ''
region = 'europe-west4'

client = dataproc_v1beta2.ClusterControllerClient(
                       client_options={
                            'api_endpoint': '{}-dataproc.googleapis.com:443'.format(region)
                        }
                    )


response = client.get_cluster(project_id, region, cluster_name)
print(response.config.endpoint_config)

In my case I get:

http_ports {
  key: "HDFS NameNode"
  value: "https://REDACTED-dot-europe-west4.dataproc.googleusercontent.com/hdfs/dfshealth.html"
}
http_ports {
  key: "Jupyter"
  value: "https://REDACTED-dot-europe-west4.dataproc.googleusercontent.com/jupyter/"
}
http_ports {
  key: "JupyterLab"
  value: "https://REDACTED-dot-europe-west4.dataproc.googleusercontent.com/jupyter/lab/"
}
http_ports {
  key: "MapReduce Job History"
  value: "https://REDACTED-dot-europe-west4.dataproc.googleusercontent.com/jobhistory/"
}
http_ports {
  key: "Spark History Server"
  value: "https://REDACTED-dot-europe-west4.dataproc.googleusercontent.com/sparkhistory/"
}
http_ports {
  key: "Tez"
  value: "https://REDACTED-dot-europe-west4.dataproc.googleusercontent.com/apphistory/tez-ui/"
}
http_ports {
  key: "YARN Application Timeline"
  value: "https://REDACTED-dot-europe-west4.dataproc.googleusercontent.com/apphistory/"
}
http_ports {
  key: "YARN ResourceManager"
  value: "https://REDACTED-dot-europe-west4.dataproc.googleusercontent.com/yarn/"
}
enable_http_port_access: true
英文:

If you have followed this doc to setup Jupyter access by enabling Component Gateway, then you can access the Web Interfaces as described here. The trick is that this is included in the API response for the v1beta2 version.

Changes needed in the code are minimal (no additional requirements apart from google-cloud-dataproc library). Just replace dataproc_v1 for dataproc_v1beta2 and access the endpoints with response.config.endpoint_config:

from google.cloud import dataproc_v1beta2

project_id, cluster_name = '', ''
region = 'europe-west4'

client = dataproc_v1beta2.ClusterControllerClient(
                       client_options={
                            'api_endpoint': '{}-dataproc.googleapis.com:443'.format(region)
                        }
                    )


response = client.get_cluster(project_id, region, cluster_name)
print(response.config.endpoint_config)

In my case I get:

http_ports {
  key: "HDFS NameNode"
  value: "https://REDACTED-dot-europe-west4.dataproc.googleusercontent.com/hdfs/dfshealth.html"
}
http_ports {
  key: "Jupyter"
  value: "https://REDACTED-dot-europe-west4.dataproc.googleusercontent.com/jupyter/"
}
http_ports {
  key: "JupyterLab"
  value: "https://REDACTED-dot-europe-west4.dataproc.googleusercontent.com/jupyter/lab/"
}
http_ports {
  key: "MapReduce Job History"
  value: "https://REDACTED-dot-europe-west4.dataproc.googleusercontent.com/jobhistory/"
}
http_ports {
  key: "Spark History Server"
  value: "https://REDACTED-dot-europe-west4.dataproc.googleusercontent.com/sparkhistory/"
}
http_ports {
  key: "Tez"
  value: "https://REDACTED-dot-europe-west4.dataproc.googleusercontent.com/apphistory/tez-ui/"
}
http_ports {
  key: "YARN Application Timeline"
  value: "https://REDACTED-dot-europe-west4.dataproc.googleusercontent.com/apphistory/"
}
http_ports {
  key: "YARN ResourceManager"
  value: "https://REDACTED-dot-europe-west4.dataproc.googleusercontent.com/yarn/"
}
enable_http_port_access: true

答案2

得分: 0

启用组件并使用以下配置:

'endpoint_config': {
    'enable_http_port_access': True
},

然后上述答案将有效:

client.get_cluster(project_id, region, cluster_name)
英文:

You need to v1beat2

Enable the component with:

'endpoint_config': {
                'enable_http_port_access': True
            },

then the above answer will work:

client.get_cluster(project_id, region, cluster_name)

huangapple
  • 本文由 发表于 2020年1月6日 21:43:27
  • 转载请务必保留本文链接:https://go.coder-hub.com/59613205.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定