Support Questions

Find answers, ask questions, and share your expertise
Announcements
Celebrating as our community reaches 100,000 members! Thank you!

How can I setting the rack ID in Ambari API?

avatar
New Contributor

I have to build a large cluster, for which I’ll need to set rack ID many times. I know two methods in Ambari Web for setting the Rack ID. http://docs.hortonworks.com/HDPDocuments/Ambari-2.1.2.0/bk_Ambari_Users_Guide/content/ch03s11.html

So I want to know if I can write a script which sets the rack ID in Ambari API

Ambari: 2.1.2.1 Hadoop: HDP2.3.0

1 ACCEPTED SOLUTION

avatar

The hosts table in the database has a field called rack_info that supports up to 255 chars. It can be edited from the UI in the Host page for a single host.

In order to edit it using the API, you can make a single request to edit it for x number of hosts. E.g.,

curl -u $username:$password -X PUT -H 'X-Requested-By:admin' http://$server:8080/api/v1/clusters/$clustername/hosts -d '{"RequestInfo":{"context":"Set Rack","query":"Hosts/host_name.in($FQDN_1,$FQDN_2,$FQDN_3)"},"Body":{"Hosts":{"rack_info":"/my_new_rack_value"}}}'

Actual call,

curl -u admin:admin -X PUT -H 'X-Requested-By:admin' http://c6401.ambari.apache.org:8080/api/v1/clusters/c1/hosts -d '{"RequestInfo":{"context":"Set Rack","query":"Hosts/host_name.in(c6401.ambari.apache.org,c6402.ambari.apache.org,c6403.ambari.apache.org)"},"Body":{"Hosts":{"rack_info":"/my_new_rack_value"}}}'

View solution in original post

3 REPLIES 3

avatar
Master Mentor
@Kai Fukazawa

Please see this

With the latest Ambari UI code you should see an option to set the rack info for each host. You can also set the rack info property through the API ...

PUT api/v1/clusters/c1/hosts/[host_name]

{
  "Hosts" : {
    "rack_info" : "/rack-01"
  } 

}

Take from https://issues.apache.org/jira/browse/AMBARI-6646

avatar

The hosts table in the database has a field called rack_info that supports up to 255 chars. It can be edited from the UI in the Host page for a single host.

In order to edit it using the API, you can make a single request to edit it for x number of hosts. E.g.,

curl -u $username:$password -X PUT -H 'X-Requested-By:admin' http://$server:8080/api/v1/clusters/$clustername/hosts -d '{"RequestInfo":{"context":"Set Rack","query":"Hosts/host_name.in($FQDN_1,$FQDN_2,$FQDN_3)"},"Body":{"Hosts":{"rack_info":"/my_new_rack_value"}}}'

Actual call,

curl -u admin:admin -X PUT -H 'X-Requested-By:admin' http://c6401.ambari.apache.org:8080/api/v1/clusters/c1/hosts -d '{"RequestInfo":{"context":"Set Rack","query":"Hosts/host_name.in(c6401.ambari.apache.org,c6402.ambari.apache.org,c6403.ambari.apache.org)"},"Body":{"Hosts":{"rack_info":"/my_new_rack_value"}}}'

avatar
New Contributor

It worked! Thank you.