Created 12-28-2016 08:43 AM
Hi, guys, I am tryign to write a autotest shell script killing the hmasters in HA mode, do you know how can I get the backup hmaster host address by using the command? I can manully find it in the ambari UI, but can not locate it by using the command
Created 12-29-2016 06:31 AM
This can be achieved with single Ambari REST API as @yusaku suggested. Following is the actual working API
{ "href" : "http://c6401.ambari.apache.org:8080/api/v1/clusters/c1/components/HBASE_MASTER?host_components/metrics/hbase/master/IsActiveMaster=true&fields=host_components/HostRoles/host_name", "ServiceComponentInfo" : { "cluster_name" : "c1", "component_name" : "HBASE_MASTER", "service_name" : "HBASE" }, "host_components" : [ { "href" : "http://c6401.ambari.apache.org:8080/api/v1/clusters/c1/hosts/c6401.ambari.apache.org/host_components/HBASE_MASTER", "HostRoles" : { "cluster_name" : "c1", "component_name" : "HBASE_MASTER", "host_name" : "c6401.ambari.apache.org" }, "metrics" : { "hbase" : { "master" : { "IsActiveMaster" : "true" } } } } ] }
Created 12-28-2016 09:40 AM
You can use the Ambari APIs to find that out using simple "curl" GET you should be able to find the Active HBase Master:
http://erie1.example.com:8080/api/v1/clusters/ErieCluster/components/HBASE_MASTER?ServiceComponentIn...
Example Output:
{ "href" : "http://erie1.example.com:8080/api/v1/clusters/ErieCluster/components/HBASE_MASTER?ServiceComponentInfo/category=MASTER&fields=ServiceComponentInfo/service_name,host_components/HostRoles/display_name,host_components/metrics/hbase/master/IsActiveMaster", "ServiceComponentInfo" : { "category" : "MASTER", "cluster_name" : "ErieCluster", "component_name" : "HBASE_MASTER", "service_name" : "HBASE" }, "host_components" : [ { "href" : "http://erie1.example.com:8080/api/v1/clusters/ErieCluster/hosts/erie3.example.com/host_components/HBASE_MASTER", "HostRoles" : { "cluster_name" : "ErieCluster", "component_name" : "HBASE_MASTER", "display_name" : "HBase Master", "host_name" : "erie3.example.com" }, "metrics" : { "hbase" : { "master" : { "IsActiveMaster" : "false" } } } }, { "href" : "http://erie1.example.com:8080/api/v1/clusters/ErieCluster/hosts/erie4.example.com/host_components/HBASE_MASTER", "HostRoles" : { "cluster_name" : "ErieCluster", "component_name" : "HBASE_MASTER", "display_name" : "HBase Master", "host_name" : "erie4.example.com" }, "metrics" : { "hbase" : { "master" : { "IsActiveMaster" : "true" } } } } ] }
Notice:
"IsActiveMaster" : "false"
.
Created 12-28-2016 10:10 AM
More easy command to access this info using curl by hitting the URL:
curl -u admin:admin -H "X-Requested-By: ambari" -X GET http://erie1.example.com:8080/api/v1/clusters/ErieCluster/hosts/erie4.example.com/host_components/HB... { "href" : "http://erie1.example.com:8080/api/v1/clusters/ErieCluster/hosts/erie4.example.com/host_components/HBASE_MASTER?fields=metrics/hbase/master/IsActiveMaster", "HostRoles" : { "cluster_name" : "ErieCluster", "component_name" : "HBASE_MASTER", "host_name" : "erie4.example.com" }, "host" : { "href" : "http://erie1.example.com:8080/api/v1/clusters/ErieCluster/hosts/erie4.example.com" }, "metrics" : { "hbase" : { "master" : { "IsActiveMaster" : "true" } } } }
.
Created 12-28-2016 06:00 PM
You should also be able to specify the condition IsActiveMaster=false to have the API respond with non-active HBaseMasters only. Instead of saying "fields=metrics/hbase/master/IsActiveMaster" in the query, you can turn that into a predicate by saying "metrics/hbase/master/IsActiveMaster=false".
Created 12-29-2016 06:31 AM
This can be achieved with single Ambari REST API as @yusaku suggested. Following is the actual working API
{ "href" : "http://c6401.ambari.apache.org:8080/api/v1/clusters/c1/components/HBASE_MASTER?host_components/metrics/hbase/master/IsActiveMaster=true&fields=host_components/HostRoles/host_name", "ServiceComponentInfo" : { "cluster_name" : "c1", "component_name" : "HBASE_MASTER", "service_name" : "HBASE" }, "host_components" : [ { "href" : "http://c6401.ambari.apache.org:8080/api/v1/clusters/c1/hosts/c6401.ambari.apache.org/host_components/HBASE_MASTER", "HostRoles" : { "cluster_name" : "c1", "component_name" : "HBASE_MASTER", "host_name" : "c6401.ambari.apache.org" }, "metrics" : { "hbase" : { "master" : { "IsActiveMaster" : "true" } } } } ] }
Created 12-30-2016 03:26 AM
Thanks, I used this url to get the backup masters
http://fsmanager:8080/api/v1/clusters/${cluster_name}/components/HBASE_MASTER?host_components/metric...
Created 12-29-2016 07:19 AM
Additionally if you due to some reason if the Ambari is down (not accessible) and still if you want to get the Active HBase Master detail then you can simply use the HBase JMX for the same. Here "16010" is HBase JMX ui port.
Exampe:
$ curl -v --silent 'http://erie4.example.com:16010/jmx?qry=Hadoop:service=HBase,name=Master,sub=Server' 2>&1 | grep isActiveMaster "tag.isActiveMaster" : "true", $ curl -v --silent 'http://erie3.example.com:16010/jmx?qry=Hadoop:service=HBase,name=Master,sub=Server' 2>&1 | grep isActiveMaster "tag.isActiveMaster" : "false",