Skip to content

Instantly share code, notes, and snippets.

@mr-jstraub
Last active April 26, 2022 10:59
Show Gist options
  • Star 7 You must be signed in to star a gist
  • Fork 5 You must be signed in to fork a gist
  • Save mr-jstraub/0b55de318eeae6695c3f to your computer and use it in GitHub Desktop.
Save mr-jstraub/0b55de318eeae6695c3f to your computer and use it in GitHub Desktop.
Ambari API - Run all Service Checks

#Ambari API - Run all Service Checks In order to check the status and stability of your cluster it makes sense to run the service checks that are included in Ambari. Usually each Ambari Service provides its own service check, but their might be services that wont include any service check at all. To run a service check you have to select the service (e.g. HDFS) in Ambari and click "Run Service Check" in the "Actions" dropdown menu.

Service Checks can be started via the Ambari API and it is also possible to start all available service checks with a single API command. To bulk run these checks it is necessary to use the same API/method that is used to trigger a rolling restart of Datanodes (request_schedules). The "request_schedules" API starts all defined commands in the specified order, its even possible to specify a pause between the commands.

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

Note: Make sure you replace user, password, clustername and ambari-server with the actual values

##Start single service check via Ambari API (e.g. HDFS Service Check):

curl -ivk -H "X-Requested-By: ambari" -u <user>:<password> -X POST -d @payload http://<ambari-server>:8080/api/v1/clusters/<clustername>/requests

Note: Since Ambari 2.2 the endpoint has changed! Now it is .../request_schedules

Payload:

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

##Start bulk Service checks via Ambari API (e.g. HDFS, Yarn, MapReduce2 Service Checks):

curl -ivk -H "X-Requested-By: ambari" -u <user>:<password> -X POST -d @payload http://<ambari-server>:8080/api/v1/clusters/<clustername>/request_schedules

Payload:

[
   {
      "RequestSchedule":{
         "batch":[
            {
               "requests":[
                  {
                     "order_id":1,
                     "type":"POST",
                     "uri":"/api/v1/clusters/<clustername>/requests",
                     "RequestBodyInfo":{
                        "RequestInfo":{
                           "context":"HDFS Service Check (batch 1 of 3)",
                           "command":"HDFS_SERVICE_CHECK"
                        },
                        "Requests/resource_filters":[
                           {
                              "service_name":"HDFS"
                           }
                        ]
                     }
                  },
                  {
                     "order_id":2,
                     "type":"POST",
                     "uri":"/api/v1/clusters/<clustername>/requests",
                     "RequestBodyInfo":{
                        "RequestInfo":{
                           "context":"YARN Service Check (batch 2 of 3)",
                           "command":"YARN_SERVICE_CHECK"
                        },
                        "Requests/resource_filters":[
                           {
                              "service_name":"YARN"
                           }
                        ]
                     }
                  },
                  {
                     "order_id":3,
                     "type":"POST",
                     "uri":"/api/v1/clusters/<clustername>/requests",
                     "RequestBodyInfo":{
                        "RequestInfo":{
                           "context":"MapReduce Service Check (batch 3 of 3)",
                           "command":"MAPREDUCE2_SERVICE_CHECK"
                        },
                        "Requests/resource_filters":[
                           {
                              "service_name":"MAPREDUCE2"
                           }
                        ]
                     }
                  }
               ]
            },
            {
               "batch_settings":{
                  "batch_separation_in_seconds":1,
                  "task_failure_tolerance":1
               }
            }
         ]
      }
   }
]

This is returned by the api

{
  "resources" : [
    {
      "href" : "http://<ambari-server>:8080/api/v1/clusters/<clustername>/request_schedules/68",
      "RequestSchedule" : {
        "id" : 68
      }
    }
  ]
}

##Payload to run all Service Checks

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

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

@ashiru
Copy link

ashiru commented Nov 30, 2017

Hey @harisekhan,

i need help in how to use this tool for my testing.

  1. do i need to use this utility from the cluster node only or commands can be triggered remotely also?
  2. is this works only for ambari?
  3. is there any tool for cloudera manager also?

Please help me in this.
Thank you in advance
Regards
Iranna

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment