PUT /api/v1/users/admin
{
"Users": {
"user_name": "admin",
"password": "newadminpassword",
"old_password": "admin"
}
}
host_new=ip-10-0-0-162.ec2.internal | |
curl -u admin:admin -i -H X-Requested-By:API -X POST http://${ambari_server}:8080/api/v1/clusters/${cluster_name}/hosts/${host_new} | |
curl -u admin:admin -i -H X-Requested-By:API -X GET http://${ambari_server}:8080/api/v1/clusters/${cluster_name}/hosts/${host_new} | |
worker_services="NODEMANAGER JOURNALNODE HDFS_CLIENT DATANODE FLUME_HANDLER METRICS_MONITOR" | |
for service in ${worker_services}; do | |
curl -u admin:admin -i -H X-Requested-By:API -X POST http://${ambari_server}:8080/api/v1/clusters/${cluster_name}/hosts/${host_new}/host_components/${service} | |
done | |
for service in ${worker_services}; do | |
curl -u admin:admin -i -H X-Requested-By:API -X PUT -d '{"HostRoles": {"state": "INSTALLED"}}' http://${ambari_server}:8080/api/v1/clusters/${cluster_name}/hosts/${host_new}/host_components/${service} | |
done | |
## todo: add a wait state here | |
for service in ${worker_services}; do | |
curl -u admin:admin -i -H X-Requested-By:API -X PUT -d '{"HostRoles": {"state": "STARTED"}}' http://${ambari_server}:8080/api/v1/clusters/${cluster_name}/hosts/${host_new}/host_components/${service} | |
done |
PUT /api/v1/users/admin
{
"Users": {
"user_name": "admin",
"password": "newadminpassword",
"old_password": "admin"
}
}
This will show you how to fetch & update configurations using the Ambari API.
In this example, we will be working with the 'hive-site' configuration.
ambari_server=172.28.128.3 ## IP or hostname of your Ambari Server
cluster_name=Sandbox ## your cluster's name
pass=admin ## your Ambari password
curl -u admin:${pass} \
http://${ambari_server}:8080/api/v1/clusters/${cluster_name}?fields=Clusters/desired_configs/hive-site
Sample result:
{
"href" : "http://172.28.128.3:8080/api/v1/clusters/Sandbox?fields=Clusters/desired_configs/hive-site",
"Clusters" : {
"cluster_name" : "Sandbox",
"version" : "HDP-2.2",
"desired_configs" : {
"hive-site" : {
"tag" : "version1418758302218100734",
"user" : "admin",
"version" : 2
}
}
}
}
tag=$(curl -u admin:${pass} \
"http://${ambari_server}:8080/api/v1/clusters/${cluster_name}?fields=Clusters/desired_configs/hive-site" \
| jq -r '.Clusters.desired_configs."hive-site".tag')
curl -u admin:${pass} \
"http://${ambari_server}:8080/api/v1/clusters/${cluster_name}/configurations?type=hive-site&tag=${tag}"
Sample result:
{
"href" : "http://172.28.128.3:8080/api/v1/clusters/Sandbox/configurations?type=hive-site&tag=version1418758302218100734",
"items" : [
{
"href" : "http://172.28.128.3:8080/api/v1/clusters/Sandbox/configurations?type=hive-site&tag=version1418758302218100734",
"tag" : "version1418758302218100734",
"type" : "hive-site",
"version" : 2,
"Config" : {
"cluster_name" : "Sandbox"
},
"properties" : {
"ambari.hive.db.schema.name" : "hive",
"datanucleus.cache.level2.type" : "none",
[... snipped the rest of the output ...]
oldconfig="$(curl -u admin:${pass} \
"http://${ambari_server}:8080/api/v1/clusters/${cluster_name}/configurations?type=hive-site&tag=${tag}")"
newconfig="$(echo ${oldconfig} \
| jq \
--arg newtag $(echo version$(date +%s%N)) '.items[]
| del(.["href", "version", "Config"])
| .tag |= $newtag
| .properties."hive.heapsize" |= "251"
| {"Clusters": {"desired_config": .}}')"
All of that explained:
- --arg newtag ...
is setting the new configuration version in the same format as Ambari Web uses
- del(
is removing fields we do not need
- .tag |=
is setting the tag to the variable we set before
- .properties."hive.heapsize"
is updating that configuration
- You would repeat with |.properties."the.config" |= "something"
for each item you wish to change
- {"Clusters ...
is adding the parent keys which Ambari expects
If you'd like to see the result, do: echo ${newconfig} | jq '.'
echo ${newconfig} | curl -u admin:${pass} \
-X PUT -H X-Requested-By:Sean -d @- \
http://${ambari_server}:8080/api/v1/clusters/${cluster_name}
{
"resources" : [
{
"href" : "http://172.28.128.3:8080/api/v1/clusters/Sandbox/configurations/service_config_versions?service_name=HIVE&service_config_version=6",
"configurations" : [
{
"clusterName" : "Sandbox",
"type" : "hive-site",
"versionTag" : "version1425390949695165000",
"version" : 5,
"serviceConfigVersions" : null,
"configs" : {
"hive.security.authenticator.manager" : "org.apache.hadoop.hive.ql.security.ProxyUserAuthenticator",
"datanucleus.cache.level2.type" : "none",
"javax.jdo.option.ConnectionPassword" : "hive",
[... SNIPPED THE REST OF THE OUTPUT ...]
"hive.heapsize" : "251",
"hive.optimize.constant.propagation" : "true",
"hive.exec.submitviachild" : "false"
},
"configAttributes" : { }
}
],
"group_id" : null,
"group_name" : null,
"service_config_version" : 6,
"service_config_version_note" : null,
"service_name" : "HIVE"
}
]
}