Using Ambari REST API
    • PDF

    Using Ambari REST API

    • PDF

    Article Summary

    Available in VPC

    Apache Ambari simplifies the management and monitoring of Hadoop clusters by providing easy-to-use web UIs and REST APIs. This guide explains how to use the Ambari REST API. For more information about Ambari REST API, refer to Ambari API reference v1..

    Compose Ambari REST API's URI

    Please create the URI of the Ambari REST API as follows:

    • AMBARI-ADDRESS: Enter the domain address assigned to the cluster
    • CLUSTER-NAME: Cluster name (Be sure to check the cluster names since they are case-sensitive)
    http://<AMBARI-ADDRESS>:8080/api/v1/clusters/<CLUSTER-NAME>
    

    Request Ambari REST API

    Send a GET request to Ambari REST API using curl.

    • example/pass123!@#: Ambari's admin account
    curl -u "example:pass123!@#" -G "http://pub-68u67.hadoop.ntruss.com:8080/api/v1/clusters/test-spark"
    

    When you run the REST API using the cluster information above, a JSON document like the one below is returned.

    # Run curl
    curl -u obj -G "http://pub-68u67.hadoop.ntruss.com:8080/api/v1/clusters/test-spark"
    {
      "href" : "http://pub-68u67.hadoop.ntruss.com:8080/api/v1/clusters/test-spark",
      "Clusters" : {
        "cluster_id" : 2,
        "cluster_name" : "SPARK",
        "health_report" : {
          "Host/stale_config" : 0,
          "Host/maintenance_state" : 0,
          "Host/host_state/HEALTHY" : 3,
          "Host/host_state/UNHEALTHY" : 0,
          "Host/host_state/HEARTBEAT_LOST" : 0,
          "Host/host_state/INIT" : 0,
          "Host/host_status/HEALTHY" : 3,
          "Host/host_status/UNHEALTHY" : 0,
          "Host/host_status/UNKNOWN" : 0,
          "Host/host_status/ALERT" : 0
    ....
    

    Parsing return value using the jq command

    You can use jq to filter or convert certain parts of the JSON document returned as a REST API result. Below is an example of filtering only the health_report information from the clusters in JSON results using jq.

    curl -u "example:pass123!@#" -G "http://pub-68u67.hadoop.ntruss.com:8080/api/v1/clusters/test-spark" | jq ".Clusters.health_report"
    {
      "Host/stale_config": 0,
      "Host/maintenance_state": 0,
      "Host/host_state/HEALTHY": 4,
      "Host/host_state/UNHEALTHY": 0,
      "Host/host_state/HEARTBEAT_LOST": 0,
      "Host/host_state/INIT": 0,
      "Host/host_status/HEALTHY": 4,
      "Host/host_status/UNHEALTHY": 0,
      "Host/host_status/UNKNOWN": 0,
      "Host/host_status/ALERT": 0
    }
    

    Example

    Getting the fully qualified domain name (FQDN) of all nodes

    curl -u "example:pass123!@#" -G "http://pub-68u67.hadoop.ntruss.com:8080/api/v1/clusters/test-spark/hosts" | jq ".items[].Hosts.host_name"
    

    Getting the FQDN of master node

    curl -u "example:pass123!@#" -G "http://pub-68u67.hadoop.ntruss.com:8080/api/v1/clusters/test-spark/services/HDFS/components/NAMENODE" | jq ".host_components[].HostRoles.host_name"
    

    Getting the FQDN of worker node

    curl -u "example:pass123!@#" -G "http://pub-68u67.hadoop.ntruss.com:8080/api/v1/clusters/test-spark/services/HDFS/components/DATANODE" | jq ".host_components[].HostRoles.host_name"
    

    Getting the internal IP address of a cluster node

    To find the IP address, you need the internal FQDN of the cluster node. First, send an Ambari query to find the FQDN of the host node, then send an Ambari query again to find the IP address of each host.

    curl -u "example:pass123!@#" -G "http://pub-68u67.hadoop.ntruss.com:8080/api/v1/clusters/test-spark/hosts/d-002-test-spark-36m-hd" | jq ".Hosts.ip"
    

    Getting default.FS

    Cloud Hadoop uses Object Storage as the default storage, and the result of the subject API is displayed as hdfs://<cluster name (namespace name)>.

    curl -u "example:pass123!@#" -G "http://pub-68u67.hadoop.ntruss.com:8080/api/v1/clusters/test-spark/configurations/service_config_versions?service_name=HDFS&service_config_version=1" | jq ".items[].configurations[].properties["fs.defaultFS"] | select(. != null)"
    

    Was this article helpful?

    Changing your password will log you out immediately. Use the new password to log back in.
    First name must have atleast 2 characters. Numbers and special characters are not allowed.
    Last name must have atleast 1 characters. Numbers and special characters are not allowed.
    Enter a valid email
    Enter a valid password
    Your profile has been successfully updated.