Skip to content

Instantly share code, notes, and snippets.

@glinmac
Last active December 23, 2020 02:00
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save glinmac/d9b1ce2e47dfbac6ad17 to your computer and use it in GitHub Desktop.
Save glinmac/d9b1ce2e47dfbac6ad17 to your computer and use it in GitHub Desktop.
ambari api examples
#!/bin/sh
AMBARI_USER=admin
AMBARI_PASSWORD=
CLUSTER_NAME=sandbox
AMBARI_API=http://127.0.0.1:8080/api/v1/clusters/$CLUSTER_NAME
BLUEPRINT_API=http://127.0.0.1:8080/api/v1/blueprints
hostname="hostname.example.com"
service="aservice"
# Stop service
curl -u $AMBARI_USER:$AMBARI_PASSWORD -i -H 'X-Requested-By: ambari' \
-X PUT \
-d "{\"RequestInfo\":{\"context\":\"Stop Service $service\"},\"Body\":{\"ServiceInfo\":{\"state\":\"INSTALLED\"}}}" \
$AMBARI_API/services/$service
# Delete service
curl -u $AMBARI_USER:$AMBARI_PASSWORD -i -H 'X-Requested-By: ambari' \
-X DELETE $AMBARI_API/services/$service
# Install component on a node
curl -u $AMBARI_USER:$AMBARI_PASSWORD -i -H 'X-Requested-By: ambari' \
-X POST $AMBARI_API/hosts/$hostname/host_components/$service
curl -u $AMBARI_USER:$AMBARI_PASSWORD -i -H 'X-Requested-By: ambari' \
-X PUT -d '{"HostRoles": {"state": "INSTALLED"}}' \
$AMBARI_API/hosts/HOSTNAME/host_components/$service
# Remove component on a node
curl -u $AMBARI_USER:$AMBARI_PASSWORD -i -H 'X-Requested-By: ambari' \
-X PUT -d '{"HostRoles": {"state": "INSTALLED"}}' \
$AMBARI_API/hosts/$hostname/host_components/$service
curl -u $AMBARI_USER:$AMBARI_PASSWORD -i -H 'X-Requested-By: ambari'\
-X DELETE $AMBARI_API/hosts/$hostname/host_components/$service
# Delete cluster
curl -u $AMBARI_USER:$AMBARI_PASSWORD -i -H 'X-Requested-By: ambari' -X DELETE $AMBARI_API
## Blueprints (https://cwiki.apache.org/confluence/display/AMBARI/Blueprints)
# Get blueprint
curl -u $AMBARI_USER:$AMBARI_PASSWORD -i -H 'X-Requested-By: ambari' -X GET $AMBARI_API?format=blueprint
# Register blueprint
curl -u $AMBARI_USER:$AMBARI_PASSWORD -i -H 'X-Requested-By: ambari' -X POST -d @topology.json $BLUEPRINT_API/topology-name
# Create cluster
curl -u $AMBARI_USER:$AMBARI_PASSWORD -i -H 'X-Requested-By: ambari' -X POST -d @cluster-creation.json $AMBARI_API
@raags
Copy link

raags commented Jul 20, 2016

Are you able to delete cluster? On 2.2 I'm not able to delete clusters.

@krishnachaitanyareddy
Copy link

@raags, were you able to delete cluster..?

@slmingol
Copy link

slmingol commented Aug 4, 2017

I do not believe you can delete through the API. This was discussed on the community site for Hortonworks - https://community.hortonworks.com/questions/17740/how-to-remove-or-delete-a-cluster.html.

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