Couldn't make PUT working :( I see there is another option https://cwiki.apache.org/confluence/display/AMBARI/Restarting+host+components+via+the+API
On Thu, Apr 9, 2015 at 8:34 AM Krzysztof Adamski <[email protected]> wrote: > almost there > Get works > curl -u admin:admin -H "X-Requested-By: ambari" -i -X GET " > http://ambari:8080/api/v1/clusters/HADOOP_LAB/components?ServiceComponentInfo/categry.in(MASTER,SLAVE)&host_components/HostRoles/host_name=host1&host_components/HostRoles/state=INSTALLED > " > > > On Thu, Apr 9, 2015 at 7:56 AM Krzysztof Adamski < > [email protected]> wrote: > >> That's it. A clever solution indeed. >> >> How about starting the services then? How to quickly exclude client >> components? >> "message" : "java.lang.IllegalArgumentException: Invalid desired state >> for a client component" >> >> There is a filter like this >> ServiceComponentInfo/category.in(SLAVE,MASTER) >> >> >> On Thu, Apr 9, 2015 at 7:41 AM Sumit Mohanty <[email protected]> >> wrote: >> >>> You can try something like this .... >>> >>> >>> curl -u admin:admin -H "X-Requested-By: ambari" -i -X PUT -d >>> '{"RequestInfo":{"context":"Stop All Host Components"},"Body":{"HostRole >>> s":{"state":"INSTALLED"}}}' "http://u1201.ambari.apache.or >>> g:8080/api/v1/clusters/c1/host_components?HostRoles/host_ >>> name=u1201.ambari.apache.org&HostRoles/state=STARTED" >>> >>> >>> Predicates such as "HostRoles/host_name=u1201.ambari.apache.org& >>> HostRoles/state=STARTED" will help narrow down the choices. >>> >>> >>> ------------------------------ >>> *From:* Krzysztof Adamski <[email protected]> >>> *Sent:* Wednesday, April 08, 2015 10:11 PM >>> *To:* [email protected] >>> >>> *Subject:* Re: Start/stop all services programmatically >>> Hi Yusaku, >>> >>> Many thanks for pointing me to the dependancies file. It would help a >>> lot. >>> >>> The problem with the *stop all* command you sent is that this for all >>> services within the cluster and I want to do this explicitly on a host >>> basis to perform a rolling OS patching. >>> Another issue is that specifying *state:INSTALL *would result in >>> installing client components on the hosts where I do not want to have them >>> e.g. data nodes. >>> Unless I did something wrong. >>> >>> Regards, >>> Krzysztof >>> >>> >>> On Thu, Apr 9, 2015 at 2:34 AM Yusaku Sako <[email protected]> >>> wrote: >>> >>>> Sorry, forgot to answer your second question regarding dependencies. >>>> Such dependencies are specified in a file called >>>> role_command_order.json as part of the stack defintion. >>>> >>>> https://github.com/apache/ambari/blob/trunk/ambari-server/sr >>>> c/main/resources/stacks/HDP/2.0.6/role_command_order.json >>>> >>>> If you try to start/stop all services in bulk, the command order >>>> rules will be followed automatically by the server. >>>> >>>> Yusaku >>>> >>>> From: Yusaku Sako <[email protected]> >>>> Reply-To: "[email protected]" <[email protected]> >>>> Date: Wednesday, April 8, 2015 5:27 PM >>>> To: "[email protected]" <[email protected]> >>>> Subject: Re: Start/stop all services programmatically >>>> >>>> Hi Krzysztof, >>>> >>>> You can do everything that the UI does with the API. >>>> The best way to learn what API calls the UI is making is to use the >>>> browser's developer tool and watch the network traffic. >>>> >>>> Stop all services: >>>> curl -i -uadmin:admin -H "X-Requested-By: ambari" -X PUT -d ' >>>> {"RequestInfo":{"context":"Stop all services","operation_level":{" >>>> level":"CLUSTER","cluster_name":"ing_hdp"}},"Body":{"Service >>>> Info":{"state":"INSTALLED"}}} >>>> ' http://ambari:8080/api/v1/clusters/ing_hdp/services >>>> >>>> Start all services: >>>> curl -i -uadmin:admin -H "X-Requested-By: ambari" -X PUT -d ' >>>> {"RequestInfo":{"context":"Start all services","operation_level":{" >>>> level":"CLUSTER","cluster_name":"ing_hdp"}},"Body":{"Service >>>> Info":{"state":"STARTED"}}} >>>> ' http://ambari:8080/api/v1/clusters/ing_hdp/services >>>> >>>> I hope this helps. >>>> Yusaku >>>> >>>> From: Krzysztof Adamski <[email protected]> >>>> Reply-To: "[email protected]" <[email protected]> >>>> Date: Tuesday, April 7, 2015 12:15 AM >>>> To: "[email protected]" <[email protected]> >>>> Subject: Start/stop all services programmatically >>>> >>>> Hello, >>>> >>>> I am busy implementing a manual job to stop all hosts services via >>>> script before rebooting the OS. The examples I found in wiki are per >>>> service or component. >>>> >>>> 1. Is there any way to invoke the stop/start for all hosts components >>>> just like from a web interface? >>>> 2. How ambari determines the proper order for the services to >>>> start/stop e.g. first stop hiveserver before stopping mysql etc. >>>> >>>> curl -s --user admin:admin -H "X-Requested-By: ambari" -X GET " >>>> http://ambari:8080/api/v1/clusters/ing_hdp/components/?Serv >>>> iceComponentInfo/category.in(SLAVE,MASTER)&host_components/H >>>> ostRoles/host_name=host1&fields=host_components/HostRoles/co >>>> mponent_name,host_components/HostRoles/state" | jq -r >>>> '[[.items[].host_components[].HostRoles.component_name]]|tostring' | >>>> sed -r 's/[\["]//g' | sed -r 's/[]]//g' >>>> >>>> function stop(){ >>>> >>>> curl -u admin:admin -i -H 'X-Requested-By: ambari' -X PUT -d >>>> '{"RequestInfo": {"context" :"Stop ‘"$1"’ via REST"}, "Body": {"HostRoles": >>>> {"state": "INSTALLED"}}}' http://ambari:8080/api/v1/clus >>>> ters/ing_hdp/hosts/host1/host_components/$1 >>>> >>>> } >>>> >>>> Thanks for any guide. >>>> >>>
