Skip to content

Instantly share code, notes, and snippets.

@jdye64
Last active March 1, 2021 18:47
Show Gist options
  • Save jdye64/edc12e9e11a92e088818 to your computer and use it in GitHub Desktop.
Save jdye64/edc12e9e11a92e088818 to your computer and use it in GitHub Desktop.
Ambari V1 REST API Reference
#!/bin/bash
# These are examples for the stable V1. They will not be broken by any future V1 releases.
# Global Variables
USER="admin"
PASS="admin"
AMBARI_HOST="localhost"
AMBARI_PORT=8080
# -------- BEGIN HDP Stack Admin Actions --------
# Link for repository version - https://github.com/apache/ambari/blob/trunk/ambari-server/docs/api/v1/repository-version-resources.md
# Gets the stack version of a particular cluster
curl -u $USER:$PASS -i -X GET http://$AMBARI_HOST:$AMBARI_PORT/api/v1/clusters/<cluster_name>/stack_versions/
# Export existing cluster configuration as an Ambari Blueprint
curl -u $USER:$PASS -i -X GET http://$AMBARI_HOST:$AMBARI_PORT/api/v1/clusters/<cluster_name>?format=blueprint
#Install a new Stack onto a cluster
curl -u $USER:$PASS -i -H 'X-Requested-By: ambari' -X POST -d '{"ClusterStackVersions": {"stack" :"HDP", "version": "2.2", "repository_version": "2.2.0.1-885"}}' http://$AMBARI_HOST:$AMBARI_PORT/api/v1/clusters/<cluster_name>/stack_versions/
# -------- END HDP Stack Admin Actions --------
# -------- BEGIN Cluster Actions --------
# List all clusters under this Ambari Server instances management
curl -u $USER:$PASS -i -X GET http://$AMBARI_HOST:$AMBARI_PORT/api/v1/clusters/
# Detailed specific cluster information
curl -u $USER:$PASS -i -X GET http://$AMBARI_HOST:$AMBARI_PORT/api/v1/clusters/<cluster-name>
# Delete a specific cluster
curl -u $USER:$PASS -i -H 'X-Requested-By: ambari' -X DELETE http://$AMBARI_HOST:$AMBARI_PORT/api/v1/clusters/<cluster-name>
# -------- END Cluster Actions ----------
# --------- BEGIN Service Actions ----------
# Start HDFS service
curl -u $USER:$PASS -i -H 'X-Requested-By: ambari' -X PUT -d '{"RequestInfo": {"context" :"Start HDFS via REST"}, "Body": {"ServiceInfo": {"state": "STARTED"}}}' http://$AMBARI_HOST:$AMBARI_PORT/api/v1/clusters/<cluster_name>/services/HDFS
# Stop HDFS service
curl -u $USER:$PASS -i -H 'X-Requested-By: ambari' -X PUT -d '{"RequestInfo": {"context" :"Stop HDFS via REST"}, "Body": {"ServiceInfo": {"state": "INSTALLED"}}}' http://$AMBARI_HOST:$AMBARI_PORT/api/v1/clusters/<cluster_name>/services/HDFS
# --------- END Service Actions ----------
# Delete an existing service
# First ensure the service is stopped
curl -u admin:admin -i -H 'X-Requested-By: ambari' -X PUT -d '{"RequestInfo":{"context":"Stop Service"},"Body":{"ServiceInfo":{"state":"INSTALLED"}}}' http://$AMBARI_SERVER_HOST:$AMBARI_PORT/api/v1/clusters/c1/services/NIFI
curl -u admin:admin -i -H 'X-Requested-By: ambari' -X PUT -d '{"RequestInfo":{"context":"Stop Service"},"Body":{"ServiceInfo":{"state":"INSTALLED"}}}' http://$AMBARI_SERVER_HOST:$AMBARI_PORT/api/v1/clusters/c1/services/NIFI
curl -u admin:admin -i -H 'X-Requested-By: ambari' -X DELETE http://$AMBARI_SERVER_HOST:$AMBARI_PORT/api/v1/clusters/c1/services/NIFI
# Done deleting existing service
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment