Created 10-12-2017 12:41 PM
Hi everyone,
i want to start all the services in ambari in time inrevals in autmated way.
like i need all the services to start daily at 7am and i want to stop at 5pm.
so that i will start the ec2-instances at 6:30am and i will stop those by 5:30pm.
can you please help me out.
thanks in advance
Created 10-12-2017 01:22 PM
You can make use fo Ambari APIs to do the same and run the following kind of API calls using curl using Cron Job at the mentioned times.
Stop All Services of an ambari managed cluster
curl -u admin:admin -H 'X-Requested-By:ambari' -X PUT -d '{"RequestInfo":{"context":"_PARSE_.STOP.ALL_SERVICES","operation_level":{"level":"CLUSTER","cluster_name":"BlueprintCluster"}},"Body":{"ServiceInfo":{"state":"INSTALLED"}}}' http://blueprint.example.com:8080/api/v1/clusters/BlueprintCluster/services?
.
Start All Services of an ambari managed cluster
curl -u admin:admin -H 'X-Requested-By:ambari' -X PUT -d '{"RequestInfo":{"context":"_PARSE_.START.ALL_SERVICES","operation_level":{"level":"CLUSTER","cluster_name":"BlueprintCluster"}},"Body":{"ServiceInfo":{"state":"STARTED"}}}' http://blueprint.example.com:8080/api/v1/clusters/BlueprintCluster/services?
Here following are the values that you will have to change:
BlueprintCluster: Replace it with your Cluster Name
blueprint.example.com: Replace it with your Ambari Server Hostname
.
Created 10-12-2017 01:22 PM
You can make use fo Ambari APIs to do the same and run the following kind of API calls using curl using Cron Job at the mentioned times.
Stop All Services of an ambari managed cluster
curl -u admin:admin -H 'X-Requested-By:ambari' -X PUT -d '{"RequestInfo":{"context":"_PARSE_.STOP.ALL_SERVICES","operation_level":{"level":"CLUSTER","cluster_name":"BlueprintCluster"}},"Body":{"ServiceInfo":{"state":"INSTALLED"}}}' http://blueprint.example.com:8080/api/v1/clusters/BlueprintCluster/services?
.
Start All Services of an ambari managed cluster
curl -u admin:admin -H 'X-Requested-By:ambari' -X PUT -d '{"RequestInfo":{"context":"_PARSE_.START.ALL_SERVICES","operation_level":{"level":"CLUSTER","cluster_name":"BlueprintCluster"}},"Body":{"ServiceInfo":{"state":"STARTED"}}}' http://blueprint.example.com:8080/api/v1/clusters/BlueprintCluster/services?
Here following are the values that you will have to change:
BlueprintCluster: Replace it with your Cluster Name
blueprint.example.com: Replace it with your Ambari Server Hostname
.
Created 10-12-2017 01:56 PM
can you please tell me how to setup cron job for the rest api
Created 10-12-2017 02:33 PM
1. Open a terminal and run the following command to open the crontab editor (it's like "vi" editor)
# crontab -e
2. Now add the following entries inside it: (here 30 17 means 5:30 PM) and similarly (30 06 means 6:30 AM)
30 17 * * * curl -u admin:admin -H 'X-Requested-By:ambari' -X PUT -d '{"RequestInfo":{"context":"_PARSE_.STOP.ALL_SERVICES","operation_level":{"level":"CLUSTER","cluster_name":"BlueprintCluster"}},"Body":{"ServiceInfo":{"state":"INSTALLED"}}}' http://blueprint.example.com:8080/api/v1/clusters/BlueprintCluster/services? 30 06 * * * curl -u admin:admin -H 'X-Requested-By:ambari' -X PUT -d '{"RequestInfo":{"context":"_PARSE_.START.ALL_SERVICES","operation_level":{"level":"CLUSTER","cluster_name":"BlueprintCluster"}},"Body":{"ServiceInfo":{"state":"STARTED"}}}' http://blueprint.example.com:8080/api/v1/clusters/BlueprintCluster/services?
.
Reference: