Created 12-28-2015 07:08 PM
How can I stop the entire HDP stack of services from the CLI? I seem to recall that there was a command to accomplish this but I can not find it. It would seem like this facility would be associated with the ambari-agent service but I did not see any such method/action on the usage for this script/service.
Created 02-19-2016 05:16 PM
You can use a script like this to perform the shutdown of a cluster. The script below will first determine the cluster's name and then use it in subsequent calls to the API.
USER=admin PASSWORD=admin AMBARI_HOST=localhost #detect name of cluster CLUSTER=$(curl -s -u $USER:$PASSWORD -i -H 'X-Requested-By: ambari' \ http://$AMBARI_HOST:8080/api/v1/clusters | \ sed -n 's/.*"cluster_name" : "\([^\"]*\)".*/\1/p') #stop all services curl -u $USER:$PASSWORD -i -H 'X-Requested-By: ambari' -X PUT \ -d '{"RequestInfo":{"context":"_PARSE_.STOP.ALL_SERVICES","operation_level":{"level":"CLUSTER","cluster_name":"Sandbox"}},"Body":{"ServiceInfo":{"state":"INSTALLED"}}}' \ http://$AMBARI_HOST:8080/api/v1/clusters/$CLUSTER/services #start all services curl -u $USER:$PASSWORD -i -H 'X-Requested-By: ambari' -X PUT \ -d '{"RequestInfo":{"context":"_PARSE_.START.ALL_SERVICES","operation_level":{"level":"CLUSTER","cluster_name":"Sandbox"}},"Body":{"ServiceInfo":{"state":"STARTED"}}}' \ http://$AMBARI_HOST:8080/api/v1/clusters/$CLUSTER/service
When you run the above you'll see a response from the API like so (NOTE: here my cluster is called "dev09_ost_hivetest_h"):
HTTP/1.1 202 Accepted User: admin Set-Cookie: AMBARISESSIONID=1t9w52ud2xali10ofo3r9uw2t4;Path=/;HttpOnly Expires: Thu, 01 Jan 1970 00:00:00 GMT Content-Type: text/plain Vary: Accept-Encoding, User-Agent Content-Length: 150 Server: Jetty(8.1.17.v20150415) { "href" : "http://localhost:8080/api/v1/clusters/dev09_ost_hivetest_h/requests/42", "Requests" : { "id" : 42, "status" : "Accepted" }
You can take the request ID ("id": 42) and monitor it to see if it's completed.
$ curl -s -u admin:admin -i -H 'X-Requested-By: ambari' http://localhost:8080/api/v1/clusters/dev09_ost_hivetest_h/requests/42 HTTP/1.1 200 OK User: admin Set-Cookie: AMBARISESSIONID=ypsi94kpge383tn0n1aosf9p;Path=/;HttpOnly Expires: Thu, 01 Jan 1970 00:00:00 GMT Content-Type: text/plain Vary: Accept-Encoding, User-Agent Content-Length: 5593 Server: Jetty(8.1.17.v20150415) { "href" : "http://localhost:8080/api/v1/clusters/dev09_ost_hivetest_h/requests/42", "Requests" : { "aborted_task_count" : 0, "cluster_name" : "dev09_ost_hivetest_h", "completed_task_count" : 16, "create_time" : 1455901657726, "end_time" : 1455901773056, "exclusive" : false, "failed_task_count" : 0, "id" : 42, "inputs" : null, "operation_level" : null, "progress_percent" : 100.0, "queued_task_count" : 0, "request_context" : "_PARSE_.STOP.ALL_SERVICES", "request_schedule" : null, "request_status" : "COMPLETED", "resource_filters" : [ ], "start_time" : 1455901657749, "task_count" : 16, "timed_out_task_count" : 0, "type" : "INTERNAL_REQUEST" }, ... ...
When it says COMPLETED, the shutdown is done.
Created 12-28-2015 07:12 PM
@Sam Mingolelli I am not sure if there was ever any single CLI command to stop entire HDP stack. But you can use Ambari APIs to start or stop all services. Refer below for the same.
https://cwiki.apache.org/confluence/pages/viewpage.action?pageId=41812517
Created 12-28-2015 07:20 PM
curl -u <USERNAME>:<PASSWORD> -H 'X-Requested-By:ambari' -X PUT -d '{"RequestInfo":{"context":"Stop All Services","operation_level":{"level":"CLUSTER","cluster_name":"cl1"}},"Body":{"ServiceInfo":{"state":"INSTALLED"}}}' http://<AMBARI-SERVER>:8080/api/v1/clusters/cl1/services
Created 12-28-2015 07:23 PM
See the following Question How to Write Cluster Startup and Shutdown Scripts with Ambari
Created 02-05-2016 08:16 PM
@Sam Mingolelli please accept the best answer or provide your own solution.
Created 02-19-2016 05:16 PM
You can use a script like this to perform the shutdown of a cluster. The script below will first determine the cluster's name and then use it in subsequent calls to the API.
USER=admin PASSWORD=admin AMBARI_HOST=localhost #detect name of cluster CLUSTER=$(curl -s -u $USER:$PASSWORD -i -H 'X-Requested-By: ambari' \ http://$AMBARI_HOST:8080/api/v1/clusters | \ sed -n 's/.*"cluster_name" : "\([^\"]*\)".*/\1/p') #stop all services curl -u $USER:$PASSWORD -i -H 'X-Requested-By: ambari' -X PUT \ -d '{"RequestInfo":{"context":"_PARSE_.STOP.ALL_SERVICES","operation_level":{"level":"CLUSTER","cluster_name":"Sandbox"}},"Body":{"ServiceInfo":{"state":"INSTALLED"}}}' \ http://$AMBARI_HOST:8080/api/v1/clusters/$CLUSTER/services #start all services curl -u $USER:$PASSWORD -i -H 'X-Requested-By: ambari' -X PUT \ -d '{"RequestInfo":{"context":"_PARSE_.START.ALL_SERVICES","operation_level":{"level":"CLUSTER","cluster_name":"Sandbox"}},"Body":{"ServiceInfo":{"state":"STARTED"}}}' \ http://$AMBARI_HOST:8080/api/v1/clusters/$CLUSTER/service
When you run the above you'll see a response from the API like so (NOTE: here my cluster is called "dev09_ost_hivetest_h"):
HTTP/1.1 202 Accepted User: admin Set-Cookie: AMBARISESSIONID=1t9w52ud2xali10ofo3r9uw2t4;Path=/;HttpOnly Expires: Thu, 01 Jan 1970 00:00:00 GMT Content-Type: text/plain Vary: Accept-Encoding, User-Agent Content-Length: 150 Server: Jetty(8.1.17.v20150415) { "href" : "http://localhost:8080/api/v1/clusters/dev09_ost_hivetest_h/requests/42", "Requests" : { "id" : 42, "status" : "Accepted" }
You can take the request ID ("id": 42) and monitor it to see if it's completed.
$ curl -s -u admin:admin -i -H 'X-Requested-By: ambari' http://localhost:8080/api/v1/clusters/dev09_ost_hivetest_h/requests/42 HTTP/1.1 200 OK User: admin Set-Cookie: AMBARISESSIONID=ypsi94kpge383tn0n1aosf9p;Path=/;HttpOnly Expires: Thu, 01 Jan 1970 00:00:00 GMT Content-Type: text/plain Vary: Accept-Encoding, User-Agent Content-Length: 5593 Server: Jetty(8.1.17.v20150415) { "href" : "http://localhost:8080/api/v1/clusters/dev09_ost_hivetest_h/requests/42", "Requests" : { "aborted_task_count" : 0, "cluster_name" : "dev09_ost_hivetest_h", "completed_task_count" : 16, "create_time" : 1455901657726, "end_time" : 1455901773056, "exclusive" : false, "failed_task_count" : 0, "id" : 42, "inputs" : null, "operation_level" : null, "progress_percent" : 100.0, "queued_task_count" : 0, "request_context" : "_PARSE_.STOP.ALL_SERVICES", "request_schedule" : null, "request_status" : "COMPLETED", "resource_filters" : [ ], "start_time" : 1455901657749, "task_count" : 16, "timed_out_task_count" : 0, "type" : "INTERNAL_REQUEST" }, ... ...
When it says COMPLETED, the shutdown is done.
Created 02-19-2016 05:27 PM
@Sam Mingolelli See this https://gist.github.com/randerzander/5b7b0e075e59f87d3c84
This is much better approach ..Thanks to @Randy Gelhausen