我有一个HDP集群&有java客户端需要在运行时下载配置文件(hdfs-site.xml,core-site.xml,hbase-site)?我该如何实现这一目标? Cloudera Manager提供了下载配置文件的URL方式,我们是否有与ambari类似的东西?
答案 0 :(得分:0)
您可以使用Ambari API或命令行实用程序下载为任何配置文件设置的属性及其值。 (但你可以用json格式下载而不是配置文件,因为它是xml格式。)
API:
步骤1:查找最新的配置版本
curl -u admin:admin -H "X-Requested-By: ambari" -X GET http://<AMBARI_SERVER_HOST>:8080/api/v1/clusters/<CLUSTER_NAME>?fields=Clusters/desired_configs
Sample OUTPUT
{
"href" : "http://AMBARI_SERVER_HOST:8080/api/v1/clusters/CLUSTER_NAME?fields=Clusters/desired_configs",
"Clusters" : {
"cluster_name" : "CLUSTER_NAME",
"version" : "HDP-2.0.6",
"desired_configs" : {
...
"mapred-site" : {
"user" : "admin",
"tag" : "version1384716039631"
}
...
}
}
}
第2步:下载配置
curl -u admin:admin -H "X-Requested-By: ambari" -X GET "http://<AMBARI_SERVER_HOST>:8080/api/v1/clusters/<CLUSTER_NAME>/configurations?type=mapred-site&tag=version1384716039631"
Sample OUTPUT
{
"href" : "http://AMBARI_SERVER_HOST:8080/api/v1/clusters/CLUSTER_NAME/configurations?type=mapred-site&tag=version1384716039631",
"items" : [
{
"href" : "http://AMBARI_SERVER_HOST:8080/api/v1/clusters/CLUSTER_NAME/configurations?type=mapred-site&tag=version1384716039631",
"tag" : "version1384716039631",
"type" : "mapred-site",
"Config" : {
"cluster_name" : "CLUSTER_NAME"
},
"properties" : {
... THESE ARE THE PROPERTY KEY-VALUE PAIRS ...
}
}]
}
使用命令行实用程序
/var/lib/ambari-server/resources/scripts/configs.sh get <ambari host> <cluster name> <config file type>
Example: /var/lib/ambari-server/resources/scripts/configs.sh get localhost Sandbox mapred-site
更多详情可参阅以下链接
https://cwiki.apache.org/confluence/display/AMBARI/Modify+configurations