Ambari Run Service Checks via API

Working on Apache Ambari using its REST APIs is fun. I have mentioned a few useful tips for using Apache Ambari‘s REST APIs, you can find a few here.

In this article I will discuss another API trick using which you can run service check for any specific service or all the services. The common services which are designed to run through Apache Ambari does include service checks. From the Ambari UI you can choose “Run Service Check” under “Actions” drop-down menu for a service.

Apache Ambari Overview

Apache Ambari is a framework which is able to provision, manage and monitor Apache Hadoop deployments. It provides easy-to-use web interface and is bundled with a collection of rich RESTful APIs.

Having said the above – I would like to add that Apache Ambari however, isn’t limited to Apache Hadoop. It can be extended to other horizons. We have a few such custom implementations which scale beyond the Hadoop ecosystem.

Apache Ambari Project

Ambari Service Check via API – Overview

The Ambari web interface is an easy method to run service check for any given service. But if you want to run the service check for one or more or all services it can be time consuming. But Ambari APIs comes to our rescue. You can execute the “service check” for a single service using the “request” API. If you have more than one services to run the “service check” against you can use “request_schedules” API. It is the same API which is used to trigger the rolling restart of slave nodes. In order to ensure a smoother execution of the “service checks” for all services, you can also provide the order for check commands and a sleep time or pause interval between execution of each check command.

Ambari Service Checks Available

Before we get into the details of how we can run “Service checks” using the API, let’s take a look at the service checks currently available for Apache Ambari for the common services.

Ambari Available Service Checks
Service Name service_name Command
HDFS HDFS HDFS_SERVICE_CHECK
YARN YARN YARN_SERVICE_CHECK
MapReduce2 MAPREDUCE2 MAPREDUCE2_SERVICE_CHECK
HBase HBASE HBASE_SERVICE_CHECK
Hive HIVE HIVE_SERVICE_CHECK
WebHCat WEBHCAT WEBHCAT_SERVICE_CHECK
Pig PIG PIG_SERVICE_CHECK
Falcon FALCON FALCON_SERVICE_CHECK
Storm STORM STORM_SERVICE_CHECK
Oozie OOZIE OOZIE_SERVICE_CHECK
ZooKeeper ZOOKEEPER ZOOKEEPER_QUORUM_SERVICE_CHECK
Tez TEZ TEZ_SERVICE_CHECK
Sqoop SQOOP SQOOP_SERVICE_CHECK
Ambari Metrics AMBARI_METRICS AMBARI_METRICS_SERVICE_CHECK
Atlas ATLAS ATLAS_SERVICE_CHECK
Kafka KAFKA KAFKA_SERVICE_CHECK
Knox KNOX KNOX_SERVICE_CHECK
Spark SPARK SPARK_SERVICE_CHECK
SmartSense SMARTSENSE SMARTSENSE_SERVICE_CHECK
Ranger RANGER RANGER_SERVICE_CHECK
HAWQ HAWQ HAWQ_SERVICE_CHECK

Ambari Service Check via API – Single Service

As mentioned earlier in the article to run the “service check” for single service you need to use the “requests” API for Apache Ambari. I will take an example of running a “service check” against YARN.

You can run the following curl command to execute the “service check” for YARN:

Please note that you will have to update the values for ambari_user, ambari_password, AMBARI_SERVER_HOST & CLUSTER_NAME with the values suitable for your cluster.

curl -u ambari_user:ambari_password -H "X-Requested-By: ambari" -X POST -d @payload http://AMBARI_SERVER_HOST:8080/api/v1/clusters/CLUSTER_NAME/requests

Payload:

{
   "RequestInfo":{
      "context":"YARN Service Check",
      "command":"YARN_SERVICE_CHECK"
   },
   "Requests/resource_filters":[
      {
         "service_name":"YARN"
      }
   ]
}

Ambari Service Check via API – Multiple Services

To execute a “service check” for more than one services you need to use “request_schedules” API for Apache Ambari. I will run a “service check” for HBase, Hive & WebHCat.

The following is how the curl command will look like:

curl -u ambari_user:ambari_password -H "X-Requested-By: ambari" -X POST -d @payload http://AMBARI_SERVER_HOST:8080/api/v1/clusters/CLUSTER_NAME/request_schedules

Payload:

[
   {
      "RequestSchedule":{
         "batch":[
            {
               "requests":[
                  {
                     "order_id":1,
                     "type":"POST",
                     "uri":"/api/v1/clusters/CLUSTER_NAME/requests",
                     "RequestBodyInfo":{
                        "RequestInfo":{
                           "context":"HBase Service Check (batch 1 of 3)",
                           "command":"HBASE_SERVICE_CHECK"
                        },
                        "Requests/resource_filters":[
                           {
                              "service_name":"HBASE"
                           }
                        ]
                     }
                  },
                  {
                     "order_id":2,
                     "type":"POST",
                     "uri":"/api/v1/clusters/CLUSTER_NAME/requests",
                     "RequestBodyInfo":{
                        "RequestInfo":{
                           "context":"Hive Service Check (batch 2 of 3)",
                           "command":"HIVE_SERVICE_CHECK"
                        },
                        "Requests/resource_filters":[
                           {
                              "service_name":"HIVE"
                           }
                        ]
                     }
                  },
                  {
                     "order_id":3,
                     "type":"POST",
                     "uri":"/api/v1/clusters/CLUSTER_NAME/requests",
                     "RequestBodyInfo":{
                        "RequestInfo":{
                           "context":"WebHCat Service Check (batch 3 of 3)",
                           "command":"WEBHCAT_SERVICE_CHECK"
                        },
                        "Requests/resource_filters":[
                           {
                              "service_name":"WEBHCAT"
                           }
                        ]
                     }
                  }
               ]
            },
            {
               "batch_settings":{
                  "batch_separation_in_seconds":1,
                  "task_failure_tolerance":1
               }
            }
         ]
      }
   }
]

The API should return a response with a “RequestSchedule” id.

Ambari Service Check via API – All Services

Just like the request provided in for multiple services, we will use the same command. The only difference will be the Payload which is passed. It will include all the services.

Payload:

[
   {
      "RequestSchedule":{
         "batch":[
            {
               "requests":[
                  {
                     "order_id":1,
                     "type":"POST",
                     "uri":"/api/v1/clusters/CLUSTER_NAME/requests",
                     "RequestBodyInfo":{
                        "RequestInfo":{
                           "context":"HDFS Service Check (batch 1 of 21)",
                           "command":"HDFS_SERVICE_CHECK"
                        },
                        "Requests/resource_filters":[
                           {
                              "service_name":"HDFS"
                           }
                        ]
                     }
                  },
                  {
                     "order_id":2,
                     "type":"POST",
                     "uri":"/api/v1/clusters/CLUSTER_NAME/requests",
                     "RequestBodyInfo":{
                        "RequestInfo":{
                           "context":"YARN Service Check (batch 2 of 21)",
                           "command":"YARN_SERVICE_CHECK"
                        },
                        "Requests/resource_filters":[
                           {
                              "service_name":"YARN"
                           }
                        ]
                     }
                  },
                  {
                     "order_id":3,
                     "type":"POST",
                     "uri":"/api/v1/clusters/CLUSTER_NAME/requests",
                     "RequestBodyInfo":{
                        "RequestInfo":{
                           "context":"MapReduce Service Check (batch 3 of 21)",
                           "command":"MAPREDUCE2_SERVICE_CHECK"
                        },
                        "Requests/resource_filters":[
                           {
                              "service_name":"MAPREDUCE2"
                           }
                        ]
                     }
                  },
                  {
                     "order_id":4,
                     "type":"POST",
                     "uri":"/api/v1/clusters/CLUSTER_NAME/requests",
                     "RequestBodyInfo":{
                        "RequestInfo":{
                           "context":"HBase Service Check (batch 4 of 21)",
                           "command":"HBASE_SERVICE_CHECK"
                        },
                        "Requests/resource_filters":[
                           {
                              "service_name":"HBASE"
                           }
                        ]
                     }
                  },
                  {
                     "order_id":5,
                     "type":"POST",
                     "uri":"/api/v1/clusters/CLUSTER_NAME/requests",
                     "RequestBodyInfo":{
                        "RequestInfo":{
                           "context":"Hive Service Check (batch 5 of 21)",
                           "command":"HIVE_SERVICE_CHECK"
                        },
                        "Requests/resource_filters":[
                           {
                              "service_name":"HIVE"
                           }
                        ]
                     }
                  },
                  {
                     "order_id":6,
                     "type":"POST",
                     "uri":"/api/v1/clusters/CLUSTER_NAME/requests",
                     "RequestBodyInfo":{
                        "RequestInfo":{
                           "context":"WebHCat Service Check (batch 6 of 21)",
                           "command":"WEBHCAT_SERVICE_CHECK"
                        },
                        "Requests/resource_filters":[
                           {
                              "service_name":"WEBHCAT"
                           }
                        ]
                     }
                  },
                  {
                     "order_id":7,
                     "type":"POST",
                     "uri":"/api/v1/clusters/CLUSTER_NAME/requests",
                     "RequestBodyInfo":{
                        "RequestInfo":{
                           "context":"PIG Service Check (batch 7 of 21)",
                           "command":"PIG_SERVICE_CHECK"
                        },
                        "Requests/resource_filters":[
                           {
                              "service_name":"PIG"
                           }
                        ]
                     }
                  },
                  {
                     "order_id":8,
                     "type":"POST",
                     "uri":"/api/v1/clusters/CLUSTER_NAME/requests",
                     "RequestBodyInfo":{
                        "RequestInfo":{
                           "context":"Falcon Service Check (batch 8 of 21)",
                           "command":"FALCON_SERVICE_CHECK"
                        },
                        "Requests/resource_filters":[
                           {
                              "service_name":"FALCON"
                           }
                        ]
                     }
                  },
                  {
                     "order_id":9,
                     "type":"POST",
                     "uri":"/api/v1/clusters/CLUSTER_NAME/requests",
                     "RequestBodyInfo":{
                        "RequestInfo":{
                           "context":"Storm Service Check (batch 9 of 21)",
                           "command":"STORM_SERVICE_CHECK"
                        },
                        "Requests/resource_filters":[
                           {
                              "service_name":"STORM"
                           }
                        ]
                     }
                  },
                  {
                     "order_id":10,
                     "type":"POST",
                     "uri":"/api/v1/clusters/CLUSTER_NAME/requests",
                     "RequestBodyInfo":{
                        "RequestInfo":{
                           "context":"Oozie Service Check (batch 10 of 21)",
                           "command":"OOZIE_SERVICE_CHECK"
                        },
                        "Requests/resource_filters":[
                           {
                              "service_name":"OOZIE"
                           }
                        ]
                     }
                  },
                  {
                     "order_id":11,
                     "type":"POST",
                     "uri":"/api/v1/clusters/CLUSTER_NAME/requests",
                     "RequestBodyInfo":{
                        "RequestInfo":{
                           "context":"Zookeeper Service Check (batch 11 of 21)",
                           "command":"ZOOKEEPER_QUORUM_SERVICE_CHECK"
                        },
                        "Requests/resource_filters":[
                           {
                              "service_name":"ZOOKEEPER"
                           }
                        ]
                     }
                  },
                  {
                     "order_id":12,
                     "type":"POST",
                     "uri":"/api/v1/clusters/CLUSTER_NAME/requests",
                     "RequestBodyInfo":{
                        "RequestInfo":{
                           "context":"Tez Service Check (batch 12 of 21)",
                           "command":"TEZ_SERVICE_CHECK"
                        },
                        "Requests/resource_filters":[
                           {
                              "service_name":"TEZ"
                           }
                        ]
                     }
                  },
                  {
                     "order_id":13,
                     "type":"POST",
                     "uri":"/api/v1/clusters/CLUSTER_NAME/requests",
                     "RequestBodyInfo":{
                        "RequestInfo":{
                           "context":"Sqoop Service Check (batch 13 of 21)",
                           "command":"SQOOP_SERVICE_CHECK"
                        },
                        "Requests/resource_filters":[
                           {
                              "service_name":"SQOOP"
                           }
                        ]
                     }
                  },
                  {
                     "order_id":14,
                     "type":"POST",
                     "uri":"/api/v1/clusters/CLUSTER_NAME/requests",
                     "RequestBodyInfo":{
                        "RequestInfo":{
                           "context":"Ambari Metrics Service Check (batch 14 of 21)",
                           "command":"AMBARI_METRICS_SERVICE_CHECK"
                        },
                        "Requests/resource_filters":[
                           {
                              "service_name":"AMBARI_METRICS"
                           }
                        ]
                     }
                  },
                  {
                     "order_id":15,
                     "type":"POST",
                     "uri":"/api/v1/clusters/CLUSTER_NAME/requests",
                     "RequestBodyInfo":{
                        "RequestInfo":{
                           "context":"Atlas Service Check (batch 15 of 21)",
                           "command":"ATLAS_SERVICE_CHECK"
                        },
                        "Requests/resource_filters":[
                           {
                              "service_name":"ATLAS"
                           }
                        ]
                     }
                  },
                  {
                     "order_id":16,
                     "type":"POST",
                     "uri":"/api/v1/clusters/CLUSTER_NAME/requests",
                     "RequestBodyInfo":{
                        "RequestInfo":{
                           "context":"Kafka Service Check (batch 16 of 21)",
                           "command":"KAFKA_SERVICE_CHECK"
                        },
                        "Requests/resource_filters":[
                           {
                              "service_name":"KAFKA"
                           }
                        ]
                     }
                  },
                  {
                     "order_id":17,
                     "type":"POST",
                     "uri":"/api/v1/clusters/CLUSTER_NAME/requests",
                     "RequestBodyInfo":{
                        "RequestInfo":{
                           "context":"Knox Service Check (batch 17 of 21)",
                           "command":"KNOX_SERVICE_CHECK"
                        },
                        "Requests/resource_filters":[
                           {
                              "service_name":"KNOX"
                           }
                        ]
                     }
                  },
                  {
                     "order_id":18,
                     "type":"POST",
                     "uri":"/api/v1/clusters/CLUSTER_NAME/requests",
                     "RequestBodyInfo":{
                        "RequestInfo":{
                           "context":"Spark Service Check (batch 18 of 21)",
                           "command":"SPARK_SERVICE_CHECK"
                        },
                        "Requests/resource_filters":[
                           {
                              "service_name":"SPARK"
                           }
                        ]
                     }
                  },
                  {
                     "order_id":19,
                     "type":"POST",
                     "uri":"/api/v1/clusters/CLUSTER_NAME/requests",
                     "RequestBodyInfo":{
                        "RequestInfo":{
                           "context":"SmartSense Service Check (batch 19 of 21)",
                           "command":"SMARTSENSE_SERVICE_CHECK"
                        },
                        "Requests/resource_filters":[
                           {
                              "service_name":"SMARTSENSE"
                           }
                        ]
                     }
                  },
                  {
                     "order_id":20,
                     "type":"POST",
                     "uri":"/api/v1/clusters/CLUSTER_NAME/requests",
                     "RequestBodyInfo":{
                        "RequestInfo":{
                           "context":"Ranger Service Check (batch 20 of 21)",
                           "command":"RANGER_SERVICE_CHECK"
                        },
                        "Requests/resource_filters":[
                           {
                              "service_name":"RANGER"
                           }
                        ]
                     }
                  },
                  {
                     "order_id":21,
                     "type":"POST",
                     "uri":"/api/v1/clusters/CLUSTER_NAME/requests",
                     "RequestBodyInfo":{
                        "RequestInfo":{
                           "context":"HAWQ Service Check (batch 21 of 21)",
                           "command":"HAWQ_SERVICE_CHECK"
                        },
                        "Requests/resource_filters":[
                           {
                              "service_name":"HAWQ"
                           }
                        ]
                     }
                  }
               ]
            },
            {
               "batch_settings":{
                  "batch_separation_in_seconds":1,
                  "task_failure_tolerance":1
               }
            }
         ]
      }
   }
]

Ambari Service Check via API – Conclusion

The “service check” for a service in Apache Ambari is a feature which can help you figure out the current status and performance of the given service. It can also be a good practice to have service checks defined for custom services specific to your environment designed to be managed via Ambari.

2 Comments

  • Hari Sekhon

    September 27, 2016 at 6:17 pm Reply

    I’ve published a CLI tool to handle all of this more easily including auto-generating the payload, inferring the cluster name and services to check etc. It has –help with lots of options, including features for –wait which tracks the progress status of the request and returns only when complete, and –cancel to stop any outstanding service checks if you accidentally launch too many by playing with the tool 🙂

    You can find it on my github here:

    https://github.com/harisekhon/pytools

    ./ambari_trigger_service_checks.py –help

    examples:

    ./ambari_trigger_service_checks.py –all

    ./ambari_trigger_service_checks.py –cancel

    ./ambari_trigger_service_checks.py –services hdfs,yarn –wait

Post a Comment

Time limit is exhausted. Please reload CAPTCHA.