Created 02-18-2018 10:50 AM
how to capture the id request number from API ?
for example we stop the service - AMBARI_METRICS
and we get the id - 128 from output , so we can use grep to capture the id , but we prefer other elegant way ,
curl -u admin:admin -i -H 'X-Requested-By: ambari' -X PUT -d '{"RequestInfo": {"context" :"Stop AMBARI_METRICS via REST"}, "Body": {"ServiceInfo": {"state": "INSTALLED"}}}' http://localhost:8080/api/v1/clusters/sys15626/services/AMBARI_METRICS
HTTP/1.1 202 Accepted
X-Frame-Options: DENY
X-XSS-Protection: 1; mode=block
X-Content-Type-Options: nosniff
Cache-Control: no-store
Pragma: no-cache
Set-Cookie: AMBARISESSIONID=19rvqn2cgzwb51sfevywdfvwm7;Path=/;HttpOnly
Expires: Thu, 01 Jan 1970 00:00:00 GMT
User: admin
Content-Type: text/plain
Vary: Accept-Encoding, User-Agent
Content-Length: 137
Server: Jetty(8.1.19.v20160209)
{
"href" : "http://localhost:8080/api/v1/clusters/sys15626/requests/128",
"Requests" : {
"id" : 128,
"status" : "Accepted"
}
Created 02-18-2018 10:58 AM
What you are seeing in the output of the API call is actually the HTTP Response which ambari has sent to the client.
{
"href": "http://localhost:8080/api/v1/clusters/sys15626/requests/128",
"Requests": {
"id": 128,
"status": "Accepted"
}
}Above is a standard API response from ambari when a request is accepted. The only option to get only the ID part is to use the response parsing mechanism provided by OS like grep. (Or using Custom parsing utility / third party APIs)
.
Example:
# cat /tmp/response.txt | grep id | awk '{print $NF}' | cut -d , -f1Created 02-18-2018 10:58 AM
What you are seeing in the output of the API call is actually the HTTP Response which ambari has sent to the client.
{
"href": "http://localhost:8080/api/v1/clusters/sys15626/requests/128",
"Requests": {
"id": 128,
"status": "Accepted"
}
}Above is a standard API response from ambari when a request is accepted. The only option to get only the ID part is to use the response parsing mechanism provided by OS like grep. (Or using Custom parsing utility / third party APIs)
.
Example:
# cat /tmp/response.txt | grep id | awk '{print $NF}' | cut -d , -f1