Our Community is getting an upgrade! To get everything ready for the relaunch, we’ll be placing the site in read-only mode starting September 21st.
We really appreciate your understanding while we get things set up behind the scenes. Catch up on all the exciting details about the move here.
Need help or have questions? Drop us a line at [email protected]

Archives of Support Questions (Read Only)

This is an archived board for historical reference. Information and links may no longer be available or relevant
Announcements
This board is archived and read-only for historical reference. To ask a new question, please post a new topic on the appropriate active board.

how to capture the last request ID

avatar

how to capture the last request ID from API , in order to trace the status ( as IN_PROCESS )

for example we run some API to restart a service , then I want to run API that will capture the last request ID

example of request "id"

{ "href" : "http://192.23.45.2.ur.com:8080/api/v1/clusters/HDP01/requests/17",

"Requests" : { "id" : 17,

"status" : "Accepted" }

Michael-Bronson
1 ACCEPTED SOLUTION

avatar
Master Mentor

@uri ben-ari

To list all the requests use the following API and see what is the maximum request ID (which will be the recent one, Higher the requestID more recent one it is):

# curl -sH "X-Requested-By: ambari" -u admin:admin -i http://localhost:8080/api/v1/clusters/Sandbox/requests?fields=Requests/request_status | grep -A 1 id | awk '{print $NF}' > /tmp/requests_details.txt;  sed -e '1,2d' -e s'/--//g'  -e 's/\n//g' -e 's/"//g' -e '/^$/d' /tmp/requests_details.txt | awk 'NR%2{printf "%s ",$0;next;}1' 

Example Output:

185, COMPLETED
186, COMPLETED
187, COMPLETED
188, FAILED
189, COMPLETED
190, COMPLETED
191, COMPLETED
193, COMPLETED
195, COMPLETED
196, COMPLETED
197, COMPLETED
198, COMPLETED
199, COMPLETED
200, COMPLETED
201, COMPLETED
202, COMPLETED
203, COMPLETED
204, COMPLETED
206, ABORTED

.

.


Then if you want to see only the IN_PROGRESS requests then you can make the following API call.

# curl -sH "X-Requested-By: ambari" -u admin:admin -i http://localhost:8080/api/v1/clusters/Sandbox/requests?fields=Requests/request_status | grep -A 1 id | awk '{print $NF}' > /tmp/requests_details.txt;  sed -e '1,2d' -e s'/--//g'  -e 's/\n//g' -e 's/"//g' -e '/^$/d' /tmp/requests_details.txt | awk 'NR%2{printf "%s ",$0;next;}1' | grep -i 'IN_PROGRESS' 

Example Output:

# curl -sH "X-Requested-By: ambari" -u admin:admin -i http://localhost:8080/api/v1/clusters/Sandbox/requests?fields=Requests/request_status | grep -A 1 id | awk '{print $NF}' > /tmp/requests_details.txt;  sed -e '1,2d' -e s'/--//g'  -e 's/\n//g' -e 's/"//g' -e '/^$/d' /tmp/requests_details.txt | awk 'NR%2{printf "%s ",$0;next;}1' | grep -i 'IN_PROGRESS' 

207, IN_PROGRESS

.

View solution in original post

1 REPLY 1

avatar
Master Mentor

@uri ben-ari

To list all the requests use the following API and see what is the maximum request ID (which will be the recent one, Higher the requestID more recent one it is):

# curl -sH "X-Requested-By: ambari" -u admin:admin -i http://localhost:8080/api/v1/clusters/Sandbox/requests?fields=Requests/request_status | grep -A 1 id | awk '{print $NF}' > /tmp/requests_details.txt;  sed -e '1,2d' -e s'/--//g'  -e 's/\n//g' -e 's/"//g' -e '/^$/d' /tmp/requests_details.txt | awk 'NR%2{printf "%s ",$0;next;}1' 

Example Output:

185, COMPLETED
186, COMPLETED
187, COMPLETED
188, FAILED
189, COMPLETED
190, COMPLETED
191, COMPLETED
193, COMPLETED
195, COMPLETED
196, COMPLETED
197, COMPLETED
198, COMPLETED
199, COMPLETED
200, COMPLETED
201, COMPLETED
202, COMPLETED
203, COMPLETED
204, COMPLETED
206, ABORTED

.

.


Then if you want to see only the IN_PROGRESS requests then you can make the following API call.

# curl -sH "X-Requested-By: ambari" -u admin:admin -i http://localhost:8080/api/v1/clusters/Sandbox/requests?fields=Requests/request_status | grep -A 1 id | awk '{print $NF}' > /tmp/requests_details.txt;  sed -e '1,2d' -e s'/--//g'  -e 's/\n//g' -e 's/"//g' -e '/^$/d' /tmp/requests_details.txt | awk 'NR%2{printf "%s ",$0;next;}1' | grep -i 'IN_PROGRESS' 

Example Output:

# curl -sH "X-Requested-By: ambari" -u admin:admin -i http://localhost:8080/api/v1/clusters/Sandbox/requests?fields=Requests/request_status | grep -A 1 id | awk '{print $NF}' > /tmp/requests_details.txt;  sed -e '1,2d' -e s'/--//g'  -e 's/\n//g' -e 's/"//g' -e '/^$/d' /tmp/requests_details.txt | awk 'NR%2{printf "%s ",$0;next;}1' | grep -i 'IN_PROGRESS' 

207, IN_PROGRESS

.